Browse Search Popular Register Upload Rules User list Login:
Search:
Little's AI Tic Tac Toe

Image:
screenshot of the scene

Author: Little

Group: Default

Filesize: 65.73 kB

Date added: 2025-07-13

Rating: 6.1

Downloads: 3076

Views: 628

Comments: 14

Ratings: 3

Times favored: 0

Made with: Algodoo v2.2.4

Tags:

Scene tag

Hi!

I recently decided I want to play Tic Tac Toe -- but unfortunately none of my friends want to.

I thought of the next best thing -- a fully functional Tic Tac Toe board in Algodoo, with an AI opponent?
While I'm at it, I'm throwing on an additional challenge: Any scene.my variables are strictly forbidden.


HOW TO PLAY

This is a classic game of Tic Tac Toe -- whichever player gets 3 of their symbol in a row wins!
When a player wins, the board will light up green and every square will fill with the winner's symbol (so if X wins, the board will fill with X's).
When a tie occurs, the board will clear itself and light up red.

After an end condition (win/tie) is reached, the board will reset itself after 2 seconds.

To place a symbol, simply click on a blank square -- it's as easy as that!
The current player's turn shows up in the top left.


To reset the board, click the gray "RESET" button below the turn indicator.


By default, AI mode is enabled.
When AI mode is enabled, the AI takes all O turns.

The AI is very simple.
It simply checks all possible moves it can make -- and if the move results in a state where the player can win, it discards it.
If the move causes the AI to win, it chooses it immediately.
And if the AI has no moves that ensure the player can't win, it gives up and throws a random move.

To disable the AI mode (for either playing against yourself or a friend!), untick the "AI mode" checkbox.:D


A game tree AI would certainly be much better, but we have to work with what we have.:lol:



2017 - 2025 Little (Random Scene)
Any item in my scenes can be used freely with credit:D

Have Phun!

EDIT: Made it smaller
Last edited at 2025/07/13 15:43:55 by Little
Please log in to rate this scene
edit
Responses to this scene
show list
Title: AI Tic_Tac_Toe
Rating: 5
Filesize: 21.36 kB
Downloads: 394
Comments: 12
Ratings: 1
Date added: 2025/07/31 11:44:09
Made with: Algodoo v2.2.3
Rating: rated 5
download
Title: Basic Tic_Tac_Toe
Rating: 5
Filesize: 8.77 kB
Downloads: 264
Comments: 0
Ratings: 1
Date added: 2025/07/27 13:07:10
Made with: Algodoo v2.2.3
Rating: rated 5
download
Nice work. Regarding "A game tree AI would certainly be much better", you can ask MS Edge Copilot to modify your Thyme code with perfect Minimax game-tree AI and it will attempt to do it.

P.S. Since the tic tac toe game tree has over 225,000 leaf nodes, I now understand why it would be difficult to do in Algodoo.

P.P.S. I now believe that a Minimax game-tree AI solution can be done in Algodoo possibly with fewer lines of custom code than are in the present scene.
Last edited at 2025/07/15 10:00:20 by s_noonan
i found a way to always win!!!, can i comment it?
Of course! :lol:
Trick question: How to find all the Tic Tac Toe games in Algobox?
This is fun!
Did you make this because of my not working scene???, because this was uploaded the day after mine was uploaded.
I think that might have been part of the inspiration (although now that you mentioned it I can't actually find that scene :( ) but this was mostly because I had recently re-opened an old game of mind and found a tic tac toe computer I had made a while ago. :lol:

I can help you make yours work though if you like!
I deleted it since i couldnt make a better solution.
@Little -- Suggestion: When either player wins, I noticed that the entire board lights up green with every square displaying the winner's O or X. When that happens, it happens so fast that the player may not know what the three winning squares were. My suggestion is, when a winner is declared, display only the winning three squares with the winner's O or X in them, rather than lighting up the entire board with O or X.


Excellent job overall! :tup: _o_ :tup:
This scene has the most concise scripting I've seen in Algobox. For example, the following code sets an array element to a specific value:
  _set := (arr, n, value)=>{
    arr(0 .. n - 1) ++ [value] ++ arr(n + 1 .. String.length(arr) - 1)
  };
It's used like this:
  _grid = _set(_grid,3,7)
  
How did you come up with that?
Last edited at 2025/07/17 10:55:55 by s_noonan
Kutis96 gave me the _set function while I was making the AHOX Codecruncher, so it's actually made by them, not me.:lol: (I do have their permission to use it though!)

Everything else the scene aside from that and maybe xfor (if xfor is used in this scene) was programmed by me though, including all of set's usecases. :lol:
Last edited at 2025/07/17 14:58:25 by Little
so good!!!:cry:
so, I tried all openings (corner, edge, center) and won all of them
I'd like an option where I play second to the ai
This is the best :]