Player class

class Player:
  def __init__(self):
    pass

  def reset(self):
    pass

  def set_maze(self, maze, entrance, exits):
    pass

  def next_node(self):
    return next_node_to_expand

  def set_node_state(self, state):
    return solution

  def get_search_tree(self):
    return search_tree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

__init__

def __init__(self):
  pass
1
2

This is the function that's called during initialisation.

This function neither takes any input nor provides outputs.

reset

def reset(self):
  pass
1
2

This is the function that reset the player to only contain the size of the maze, and the information of the entrance, as if we have only called __init__() and set_maze(...).

This function neither takes any input nor provides outputs.

set_maze

def set_maze(self, maze, entrance, exits):
  pass
1
2

This is the function to receive the information of maze from the maze application.

This function takes three positional inputs, maze, entrance, and exits.

maze = {
  "n_row": 5,
  "n_col": 7
}
1
2
3
4

maze["n_row"] gives the number of rows of the maze.

maze["n_col"] gives the number of columns of the maze.

entrance = {
  "position": [2,1],
  "actions": "nswe",
  "entrance": True,
  "exit": False
}
1
2
3
4
5
6

entrance["position"] gives the coordinates of the cell.

entrance["actions"] gives the available actions from the cell (north, south, west, east).

entrance["entrance"] is True if it's an entrance else False.

entrance["exit"] is True if it's an exit else False.

This is in the same format as the other node state provided by the maze.

exits = [[3,3], [2,2]]
1

exits is a list of coordinates for the exits.

next_node

def next_node(self):
  return next_node_to_expand
1
2

This function returns the next node to be expanded. The output will be sent to maze application to request for information.

next_node_to_expand = [1,3]

set_node_state

def set_node_state(self, state):
  return solution
1
2

The maze application sends the state of a node using this function.

This function takes one input, state, and gives one output, solution.

state = {
  "position": [3,4],
  "actions": "nw",
  "entrance": False,
  "exit": False
}
1
2
3
4
5
6

state["position"] gives the coordinates of the cell.

state["actions"] gives the available actions from the cell (north, south, west, east).

state["entrance"] is True if it's an entrance else False.

state["exit"] is True if it's an exit else False.

solution = {
  "found": False,
  "solution": []
}

solution = {
  "found": True,
  "solution": [[1,2], [1,3], [2,3], [3,3]]
}
1
2
3
4
5
6
7
8
9

solution["found"] is True if solution is found else False.

solution["solution"] gives the solution (sequence of cells) if solution["found"] is True else [].

get_search_tree

def get_search_tree(self):
  return search_tree
1
2

This function returns the search tree up to the current stage. This function does not take any input.

The output of the function is a list/array of the nodes in the search tree.

search_tree = [{
  'id': 1,
  'state': [1,1],
  'children': [2,3,4],
  'actions': ['n','s','e'],
  'removed': False,
  'parent': None
}, ...]
1
2
3
4
5
6
7
8

Each node has a unique id.

state is the coordinates of a cell.

children is a list of the ids of its children. If there is no children, it should be [].

search_tree = [{
  'id': 1,
  'state': [1,1],
  'children': [2,3,4],
  'actions': ['n','s','e'],
  'removed': False,
  'parent': None
}, ...]
1
2
3
4
5
6
7
8

actions is a list of actions that lead to its children, the sequence is corresponding to the sequence of children.

removed is True if the node is removed and will not be expanded.

parent is the id of its parent. The root node/initial state has no parent, and therefore it is None.

Example of search tree

search_tree = [{
  'id': 1,
  'state': [1,1],
  'children': [2,3,4],
  'actions': ['n','s','e'],
  'removed': False,
  'parent': None
}, {
  'id': 2,
  'state': [1,2],
  'children': [5,6,7],
  'actions': ['n','s','w'],
  'removed': False,
  'parent': 1
}, {
  'id': 3,
  'state': [1,0],
  'children': [8,9],
  'actions': ['n','w'],
  'removed': False,
  'parent': 1
}, {
  'id': 4,
  'state': [2,1],
  'children': [],
  'actions': [],
  'removed': True,
  'parent': 1
}, {
  'id': 5,
  'state': [1,3],
  'children': [10,11],
  'actions': ['n','s','w'],
  'removed': False,
  'parent': 2
}, {
  'id': 6,
  'state': [1,1],
  'children': [],
  'actions': [],
  'removed': True,
  'parent': 2
}, {
  'id': 7,
  'state': [0,2],
  'children': [12,13],
  'actions': ['n','s'],
  'removed': False,
  'parent': 2
}, {
  'id': 8,
  'state': [1,1],
  'children': [],
  'actions': [],
  'removed': False,
  'parent': 3
}, {
  'id': 9,
  'state': [0,0],
  'children': [],
  'actions': [],
  'removed': False,
  'parent': 3
}, {
  'id': 10,
  'state': [1,4],
  'children': [],
  'actions': [],
  'removed': False,
  'parent': 5
}, {
  'id': 11,
  'state': [1,2],
  'children': [],
  'actions': [],
  'removed': True,
  'parent': 5
}, {
  'id': 12,
  'state': [0,3],
  'children': [],
  'actions': [],
  'removed': False,
  'parent': 7
}, {
  'id': 13,
  'state': [0,1],
  'children': [],
  'actions': [],
  'removed': False,
  'parent': 7
}]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
1 • 1 1 • 2 n 1 • 0 s 2 • 1 e 1 • 3 n 1 • 1 s 0 • 2 w 1 • 1 n 0 • 0 w 1 • 4 n 1 • 2 s 0 • 3 n 0 • 1 s

A sample player is provided as players/test_player.

Last Updated: 5/5/2020, 10:47:57 PM