Spaces:
Runtime error
Runtime error
Sasha Rush
commited on
Delete prompt.py
Browse files
prompt.py
DELETED
|
@@ -1,160 +0,0 @@
|
|
| 1 |
-
import io
|
| 2 |
-
from contextlib import redirect_stdout
|
| 3 |
-
tab = " "
|
| 4 |
-
|
| 5 |
-
def animate(board, actions, show=False):
|
| 6 |
-
print(tab + "p = ", board.player_pos )
|
| 7 |
-
for i, action in enumerate(actions):
|
| 8 |
-
#print(tab + "# Illegal next actions:", ",".join([m.value + " " + str(add(board.player_pos, Board.change(m))) for m, msg in board.illegal_moves()]))
|
| 9 |
-
for m, msg in board.illegal_moves():
|
| 10 |
-
#if msg is not None:
|
| 11 |
-
# print(tab + msg)
|
| 12 |
-
pass
|
| 13 |
-
new_board, msg = board.move(action)
|
| 14 |
-
print(tab + f"# {action.value} {Board.change(action)} Next? {new_board.player_pos} Wall? {new_board.player_pos in new_board.wall_pos}")
|
| 15 |
-
print(tab + "p = move(b, \"" + action.value + "\", p)", f"# {new_board.player_pos} Next Goal:", new_board.key_pos if new_board.key_pos else new_board.flag_pos)
|
| 16 |
-
#print(tab + "assert pos ==", new_board.player_pos)
|
| 17 |
-
#print("\t# Active walls (only illegal positions):", ",".join(map(str, new_board.wall_pos)))
|
| 18 |
-
#print("\t# Boundary is:", add(new_board.flag_pos, (1 , 1)))
|
| 19 |
-
#print("\tpos = ", str(new_board.player_pos))
|
| 20 |
-
#print("\tassert pos not in board.walls")
|
| 21 |
-
|
| 22 |
-
# print("\tassert pos[0] < 5")
|
| 23 |
-
# print("\tassert pos[1] < 5")
|
| 24 |
-
# if (i + 1) % 3 == 0:
|
| 25 |
-
# print("Board after actions")
|
| 26 |
-
# print()
|
| 27 |
-
if show:
|
| 28 |
-
print(new_board)
|
| 29 |
-
# print()
|
| 30 |
-
#print(f'\nActions ({every} total):')
|
| 31 |
-
board = new_board
|
| 32 |
-
return board
|
| 33 |
-
|
| 34 |
-
f = io.StringIO()
|
| 35 |
-
with redirect_stdout(f):
|
| 36 |
-
print("# Consider a game on a hexagonal grid. Your objective is make legal action to get pickup a key and to reach a goal position. Here are the moves.")
|
| 37 |
-
|
| 38 |
-
#board = Board.create_empty_board((5, 5)).create_wall((4, 4)).move(Actions.DOWN).move(Actions.RIGHT)
|
| 39 |
-
comment = "change = {"
|
| 40 |
-
for action in Actions:
|
| 41 |
-
comment += f"{tab}\"{action.value}\" : {Board.change(action)}, \n"
|
| 42 |
-
comment += "}"
|
| 43 |
-
out = f"""
|
| 44 |
-
{comment}
|
| 45 |
-
def move(board, action, old_pos):
|
| 46 |
-
# ACTIONS (must be legal)
|
| 47 |
-
offet = change[action]
|
| 48 |
-
board.move(action)
|
| 49 |
-
pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
|
| 50 |
-
assert 0 <= pos[0] < board.boundary[0]
|
| 51 |
-
assert 0 <= pos[1] < board.boundary[1]
|
| 52 |
-
assert pos not in board.walls
|
| 53 |
-
if action == "PU":
|
| 54 |
-
assert pos == board.key
|
| 55 |
-
return pos
|
| 56 |
-
"""
|
| 57 |
-
print(out)
|
| 58 |
-
# print("\tupdate(board, ", Board.change(action) , ")")
|
| 59 |
-
# print("\tpos = board.player_pos")
|
| 60 |
-
# print("\tassert 0 <= pos[0] < 5")
|
| 61 |
-
# print("\tassert 0 <= pos[1] < 5")
|
| 62 |
-
# print("\tassert pos not in board.walls")
|
| 63 |
-
# print("\treturn pos")
|
| 64 |
-
print()
|
| 65 |
-
|
| 66 |
-
print("# Pickup can only be called on the Key position. These are the only valid actions.")
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
# print()
|
| 70 |
-
# print(board.player_pos)
|
| 71 |
-
# print('\nActions (1 total):')
|
| 72 |
-
# print(action)
|
| 73 |
-
# new_board = board.move(action)
|
| 74 |
-
# print()
|
| 75 |
-
# print("Board after actions")
|
| 76 |
-
# print()
|
| 77 |
-
# print(new_board.player_pos)
|
| 78 |
-
# print()
|
| 79 |
-
ex = 0
|
| 80 |
-
print("# Here is an example: ")
|
| 81 |
-
def example(board, actions, show=False):
|
| 82 |
-
global ex
|
| 83 |
-
ex += 1
|
| 84 |
-
print("#-------------")
|
| 85 |
-
print("# EXAMPLE:")
|
| 86 |
-
print(f"def example{ex}():")
|
| 87 |
-
print(f"{tab}b = GameBoard(", board.board_state2(), ")")
|
| 88 |
-
board = animate(board,
|
| 89 |
-
actions, show)
|
| 90 |
-
print(f"{tab}return b")
|
| 91 |
-
print(f"#--------------")
|
| 92 |
-
|
| 93 |
-
board = Board.create_empty_board((5, 5), (0, 2), (4, 4), (0, 0) ).create_wall((2, 2))
|
| 94 |
-
actions = [Actions.RIGHT, Actions.PICKUP, Actions.DOWNLEFT, Actions.DOWNLEFT, Actions.DOWNRIGHT, Actions.RIGHT, Actions.DOWNRIGHT]
|
| 95 |
-
example(board, actions)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
board = Board.create_empty_board((5, 5), (4, 0), (0, 0), (4, 4)).create_wall((2, 0)).create_wall((2, 4))
|
| 99 |
-
actions = [Actions.LEFT, Actions.LEFT, Actions.PICKUP, Actions.UPRIGHT, Actions.UPRIGHT, Actions.UPLEFT, Actions.UPLEFT]
|
| 100 |
-
example(board, actions)
|
| 101 |
-
|
| 102 |
-
board = Board.create_empty_board((5, 5), (2, 0), (4, 4), (0, 0)).create_wall((2,2)).create_wall((3,1))
|
| 103 |
-
actions = [Actions.DOWNRIGHT, Actions.DOWNLEFT, Actions.PICKUP, Actions.UPRIGHT, Actions.RIGHT, Actions.DOWNRIGHT, Actions.DOWNLEFT, Actions.DOWNRIGHT]
|
| 104 |
-
example(board, actions)
|
| 105 |
-
|
| 106 |
-
#print("# This example shows a failure that is fails because of an assertion.")
|
| 107 |
-
#board = Board.create_empty_board((5, 5), (2, 0), (4, 4), (0, 0)).create_wall((0,2))
|
| 108 |
-
# actions = [Actions.RIGHT]
|
| 109 |
-
# example(board, actions)
|
| 110 |
-
|
| 111 |
-
# board = Board.create_empty_board((4, 4)).create_wall((0, 1))
|
| 112 |
-
# actions = [Actions.DOWN, Actions.DOWN, Actions.DOWN, Actions.RIGHT, Actions.RIGHT, Actions.RIGHT]
|
| 113 |
-
# example(board, actions)
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
# board = Board.create_empty_board((4, 4)).create_wall((1, 0)).create_wall((3, 3))
|
| 117 |
-
# actions = [Actions.DOWN, Actions.RIGHT, Actions.DOWN, Actions.DOWN, Actions.DOWN, Actions.RIGHT, Actions.RIGHT]
|
| 118 |
-
# example(board, actions)
|
| 119 |
-
# print()
|
| 120 |
-
# print(board)
|
| 121 |
-
print("""
|
| 122 |
-
# ----
|
| 123 |
-
# Retry EXAMPLE:
|
| 124 |
-
def example4():
|
| 125 |
-
b = GameBoard( init=(0, 0), flag=(4, 4), walls= [(1, 1), (3, 1)], boundary= (5, 5), key= (2, 0) )
|
| 126 |
-
p = (0, 0)
|
| 127 |
-
# DR (1, 1) Next? (1, 1) Wall? True (trying again)
|
| 128 |
-
# R (0, 2) Next? (2, 0) Wall? False
|
| 129 |
-
p = move(b, "R", p)
|
| 130 |
-
...
|
| 131 |
-
#---
|
| 132 |
-
""")
|
| 133 |
-
|
| 134 |
-
print("# It is illegal to take actions that move you to any position with: active walls in the example, less than 0, or strictly outside the boundary.")
|
| 135 |
-
print("# Do not move to these position or you will fail. To pick-up the key you must first move to its position. It is legal to be on the same position as the key." )
|
| 136 |
-
print("# You will likely need to go back to the same positions that you have been in before after picking up the key, that is allowed." )
|
| 137 |
-
|
| 138 |
-
print("# List the illegal action in a truthful manner. Every action is legal if it is in bounds and is not a wall. Walls are always illegal.")
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
board = Board.create_empty_board((8, 15), (3, 1), (7, 13), (0, 0)).create_wall((2, 2)).create_wall((1, 1)).create_wall((5, 3)).create_wall((1, 11)).create_wall((5, 5)).create_wall((6, 6)).create_wall((6, 10)).create_wall((2, 6)).create_wall((4, 12))
|
| 142 |
-
print()
|
| 143 |
-
print()
|
| 144 |
-
print("# Contraints for this example:", board.board_state())
|
| 145 |
-
|
| 146 |
-
#print("# The following comments shows the action that are used in order")
|
| 147 |
-
#print("# ")
|
| 148 |
-
print()
|
| 149 |
-
print("")
|
| 150 |
-
print(f"# The following function shows the actions that are used to move from position 0,0 to the end goal without hitting a wall.")
|
| 151 |
-
|
| 152 |
-
# print("def example():")
|
| 153 |
-
# #print("\n" + tab + "# Start:")
|
| 154 |
-
# print(tab + "# Contraints for this example:", board.board_state())
|
| 155 |
-
# print(f"{tab}b = GameBoard(", board.board_state2(), ")")
|
| 156 |
-
#print("# Contraints for this example:", board.board_state())
|
| 157 |
-
#print(f"board = GameBoard(", board.board_state2(), ")")
|
| 158 |
-
#print(f"# The following codes shows the actions that are used to move from position 0,0 to the end goal without hitting a wall.")
|
| 159 |
-
out = f.getvalue()
|
| 160 |
-
print(out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|