Efficient algorithm for counting unique states of tic tac toe

后端 未结 6 838
抹茶落季
抹茶落季 2021-02-07 12:51

I\'m trying to build a tic tac toe game to demonstrate and experiment with machine learning algorithms, and i\'ve found an interesting problem.

eg: a tic tac toe board c

6条回答
  •  清酒与你
    2021-02-07 13:09

    I don't know the proper mathematical way, but I'd do it like this. Devise a way to convert any state to one number. For instance, assign empty field to zero, O piece to 1, X piece to 2, and treat 9 digits as a number in base-3 system. Now, transform the state to all 7 remaining mirror states. Calculate their numbers too. Pick the smallest out of those 8 numbers. That's it.

提交回复
热议问题