I'm writing a project for a Python coding class and I have a question. I'm writing a Reversi engine that will look several moves ahead in a game and then pick the move that it thinks is best. While I understand that python isn't an ideal language for this (because it's not as fast as some other languages), I think that it's possible to write code that is at least functional while still maybe being a little slow.
That being said, I am in the process of trying to create two tables: a game board (think a matrix) and a game tree that will hold integers. I want to use something memory-efficient and fast to append, delete, and read entries.
The board that I am using right now is not very efficient. I wanted to ask what modules anyone would suggest (with instructions on how to use them) to write something that would make an equivalent of this but lighter on memory (examples: array, numpy; except I don't know how to use either of these):
self.board = [[0, 0, 0, 0, 0, 0, 0, 0,],
[0, 0, 0, 0, 0, 0, 0, 0,],
[0, 0, 0, 0, 0, 0, 0, 0,],
[0, 0, 0, 1, 2, 0, 0, 0,],
[0, 0, 0, 2, 1, 0, 0, 0,],
[0, 0, 0, 0, 0, 0, 0, 0,],
[0, 0, 0, 0, 0, 0, 0, 0,],
[0, 0, 0, 0, 0, 0, 0, 0,]]
For the game tree, I have ideas depending on how lightweight a list of lists should be. An idea that I'm working with written in standard python is similar to:
tree_zero = %
tree_one = [%, %, %]
tree_two = [[%, %, %], [%, %, %], [%, %, %]]
tree_thre = [[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]]],
tree_four = [[[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]]],
[[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]]],
[[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]],
[[%, %, %], [%, %, %], [%, %, %]]]]
Where each % would be one of the boards given above (and is more than ideal: not every turn has exactly three options). But this is a slow and heavy object that is difficult for python to use memory-efficiently (especially if I go deeper than 4-ply).
If anyone has worked with programs like this before or has ideas of efficient modules to import let me know!
For an example of a game tree, think of the Wikipedia page and especially the first picture on the page.
EDIT: Ideally, I would like to look further than four moves ahead, this is just an example of how the first four levels would look. Also, there will be multiple copies of the given trees floating around for use. Speed is important for something that grows exponentially like this.