Ask HN: How would you design an API for a Python minimax library?
I want to start writing blog posts, and I've decided that I want to write a series about the Minimax algorithm, as it's something that I've done before (as in I've written a game ai using minimax before) but I could definitely learn more about and there's plenty of interesting topic to get into (i.e. optimization like alpha-beta pruning, probability, designing evaluation function, memoization and transposition tables).
I'd like to make this a more general library instead of having to remake the code every time I want to switch to a different game or system, but I'm having trouble deciding how I want to design the API. Here's what I'd need from the user, as far as I'm aware:
* A definition of the current "state"
* A function to generate a list of "moves" from that "state"
* A function that changes the state based on a "move" from that move list
* An evaluation function that takes in the "state" and returns a real number
* A way to swap the current "state" to the opponent's "state"
From what I'm thinking, this looks like the perfect situation for object oriented programming. You'd have the user define an immutable "State" class that would have "move", "generate_move_list", "evaluate", and "opponent", and all of that state information would be handled within the class. The API would define an abstract class of some kind.
This thought comes from having more experience in Java that Python, and from what I've seen that wouldn't be how most people make python libraries, so I've come to ask the opinions of people with more experience that me. What do you guys think?
0 comments
[ 3.4 ms ] story [ 7.3 ms ] threadNo comments yet.