我已经制作了无与伦比的井字棋 AI,但我想制作它 "dumber"

I've made an unbeatable Tic Tac Toe AI, but I'd want to make it "dumber"

我使用以下规则制作了井字棋 AI:(https://en.wikipedia.org/wiki/Tic-tac-toe)

Win: If the player has two in a row, they can place a third to get three in a row.

Block: If the opponent has two in a row, the player must play the third themselves to block the opponent.

Fork: Create an opportunity where the player has two threats to win (two non-blocked lines of 2). Blocking an opponent's fork:

  • Option 1: The player should create two in a row to force the opponent into defending, as long as it doesn't result in them creating a fork. For example, if "X" has a corner, "O" has the center, and "X" has the opposite corner as well, "O" must not play a corner in order to win. (Playing a corner in this scenario creates a fork for "X" to win.)

  • Option 2: If there is a configuration where the opponent can fork, the player should block that fork.

Center: A player marks the center. (If it is the first move of the game, playing on a corner gives "O" more opportunities to make a mistake and may therefore be the better choice; however, it makes no difference between perfect players.)

Opposite corner: If the opponent is in the corner, the player plays the opposite corner.

Empty corner: The player plays in a corner square.

Empty side: The player plays in a middle square on any of the 4 sides.

所以现在,我想实现某种系统,动态地改变它的难度。

要构建一个不完美的 AI,您可以根据它们的好坏对所有可能的动作进行排序,然后不要总是选择最好的。

最好的应该始终是您的规则列表给出的那个,但是您必须定义所有其他组合的值(即,如果有可能连续放置第三个,则玩角落,这是不是那个角落等)。

您可以根据难度应用上述规则的某些子集,例如:

简单 - 拦网、空角、空边、获胜

中等 - 方块、中路、空角、空边、胜利

困难 - 拦网、中路、空角、空边、对角、获胜

疯狂 - 街区,叉子,中心,空角,空边,对角,赢

实现起来并不难,只需添加一个绑定到难度单选按钮的类型枚举,该单选按钮在开始时会停用。然后检查每项检查的难度:

If(some stuff && difficulty.In("HARD", "INSANE")) 
    OppositeCorner();