27
loading...
This website collects cookies to deliver better user experience
utilities
directory. Running utilities/make_food_plays.py
generates all the possible positions for food in a 5x5 matrix (about 16.7 million of them). It then weights the possible moves on each board based on food proximity and how much food is in each quadrant.for loc, value in enumerate(board):
if value == 'O':
x_diff = loc % board_size
y_diff = loc // board_size
x_weight = head - abs(x_diff - head)
y_weight = head - abs(y_diff - head)
# left
if x_diff < head:
preferred["left"] += 1 + x_weight + y_weight
# right
if x_diff > head:
preferred["right"] += 1 + x_weight + y_weight
# down
if y_diff < head:
preferred["down"] += 1 + x_weight + y_weight
# up
if y_diff > head:
preferred["up"] += 1 + x_weight + y_weight
best_move_score = max(preferred, key=preferred.get)
JSON
records of all the boards and uses the Algolia Python client to import the records into an Algolia index.def update_index(plays: str, index: str = ''):
# Create the index
print("Updating index {}".format(index))
client = SearchClient.create(os.getenv('APP_ID'), os.getenv('API_KEY'))
index = client.init_index(index)
index.clear_objects()
index.save_objects(plays)
server_logic.py
, then build a string representing a 5x5 field around her head. I use this string to query the Algolia index in find_boards.py
to get the best moves from the list of possible boards. All the "smarts" are in the board generator, so I can work to constantly improve Searchy's vision without putting more drag on these real time queries.