Minimax Sketch

You are with “tic-tac-dum”: two players try to get 3 marks in a row on a one-dimensional board.

Board: an array of integers.

Legal moves are any unoccupied square.

Move

A Move is a player and a position.

Game State

A GameState contains:

  • Board
  • Current player

Remember to make a copy of the game state every time you want to change it; do not modify it.

Method: play(self, move) returns a new, modified game state.

Scoring system

This has been simplified since our class discussion.

  • One piece that could become three in a row (so two empty spaces) somewhere around it: 10 points
  • Two pieces that could become three in a row: 100 points.
  • Three pieces in a row: 9999 points.

Write and test the scoring system.

Move Selection

The key function to write is best_score_move, which returns a tuple containing the score and the move that it recommends given a game state and a depth to search.

This is the signature of the function I used:

def best_score_move(g: GameState, depth: int = 1) -> Tuple[int, Move]:
	pass

Testing Setup

This is a piece of my tester code. Your setup can be different.

import unittest
class MachineTester(unittest.TestCase):
	def test_scoring_2(self):
		game = GameState([99, 1, 0, 0, 1, 99],1)
		ans = score(game)
		correct = 20
		self.assertEqual(correct, ans, "SCORE 2: Fully score |X__X|")