# Babylon JS Tic-Tac-Toe Challenge

**URL:** https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343
**Category:** Demos and projects
**Created:** [December 5, 2020, 1:48pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343 "2020-12-05T13:48:38Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 5, 2020, 1:48pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/1 "2020-12-05T13:48:38Z")

</div>

[Tic-Tac-Toe](https://en.wikipedia.org/wiki/Tic-tac-toe) – one of the most ancient board games in human history. It is also the classic programming exercise, an instance of an [m,n,k-game](https://en.wikipedia.org/wiki/M,n,k-game), where two players alternate taking turns on an m×n board until one of them gets k in a row.

With the help of Babylon JS it is now possible to visualize and play, for example, tic-tac-toe in 3x3x3 cube; or to put the board onto the surface of [cylinder](https://forum.babylonjs.com/t/tic-tac-toe-on-cylinder/16303) (or even torus knot), or use another numerous 3D variations of this game. It is real fun!

So the Tic-Tac-Toe challenge is open!

Meanwhile meet Babylon JS Tic-Tac-Toe #1 – classic version, rough and dirty, but with particles (and some animation too) 🙂

[https://playground.babylonjs.com/#2WR12Z#2](https://playground.babylonjs.com/#2WR12Z#2)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/c/c020f67f5175b553a86ff885a089ed3171ca6ac6.jpeg)

---

<div class="post-metadata">

### Author: ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)
#### Post date: [December 5, 2020, 4:40pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/2 "2020-12-05T16:40:46Z")

</div>

Love yours already!

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/ff7f4b0a0a2b48084ba83fcb2e049bcff0e06038.jpeg)

---

<div class="post-metadata">

### Author: ![msDestiny14](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/msdestiny14/32/9572_2.png) [@msDestiny14](https://forum.babylonjs.com/u/msDestiny14)
#### Post date: [December 5, 2020, 4:52pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/4 "2020-12-05T16:52:40Z")

</div>

OMG! Was this based on that other forum post? 😍 You beat me to it. Love it!

---

<div class="post-metadata">

### Author: ![2kplusone](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/2kplusone/32/12674_2.png) [@2kplusone](https://forum.babylonjs.com/u/2kplusone)
#### Post date: [December 5, 2020, 5:14pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/5 "2020-12-05T17:14:49Z")

</div>

I can’t wait to post my cylinder one. 😃 Thanks for doing this. So cool!

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 5, 2020, 5:36pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/6 "2020-12-05T17:36:05Z")

</div>

One could think about 3x3x3 or 4x4x4 etc. game interface (how to make inner moves) - it is not the trivial task!

---

<div class="post-metadata">

### Author: ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)
#### Post date: [December 6, 2020, 8:03pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/7 "2020-12-06T20:03:04Z")

</div>

This is really nice but do you think you could make the AI player a bit more challenging. It seems to often pick the worst choice of option to counter my move and winning is just too easy.

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 6, 2020, 8:20pm UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/8 "2020-12-06T20:20:21Z")

</div>

Currently AI moves are random; it is possible to make AI more “clever” (even unbeatable, if AI will move first, as we know from the game theory).  
Here is very good article about JS minimax algorithm - [https://alialaa.com/blog/tic-tac-toe-js-minimax](https://alialaa.com/blog/tic-tac-toe-js-minimax)  
I didn’t implement it here since it is actually a quick draft and the game is too simple. But it definitely will be very interesting to use in more complex versions, for example in 3x3x3 board, as well as in other games where one needs a good and strong AI.  
Still my version is good for very small kids - if they will think they will always win 🙂

---

<div class="post-metadata">

### Author: ![REX\_DUNGEUR](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rex_dungeur/32/17559_2.png) [@REX\_DUNGEUR](https://forum.babylonjs.com/u/REX_DUNGEUR)
#### Post date: [December 12, 2020, 10:47am UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/9 "2020-12-12T10:47:25Z")

</div>

Easy and cool!

 ![Screenshot from 2020-12-12 09-37-00](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/fe8311a0f8f696df4486ff69d8e7f1cee58f9f8d.jpeg)

---

<div class="post-metadata">

### Author: ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)
#### Post date: [December 29, 2022, 10:26am UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/10 "2022-12-29T10:26:05Z")

</div>

Here is the unbeatable version - [https://yuka.babylonpress.org/examples/js/graph/tictactoe/](https://yuka.babylonpress.org/examples/js/graph/tictactoe/)🙂

---

<div class="post-metadata">

### Author: ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)
#### Post date: [December 29, 2022, 10:34am UTC](https://forum.babylonjs.com/t/babylon-js-tic-tac-toe-challenge/16343/11 "2022-12-29T10:34:33Z")

</div>

Thanks for sharing. It’s much better indeed. Now, the only problem is the game doesn’t offer enough possibilities. I couldn’t beat the AI out of 10 games… but then, it always ended up the same 😜

 ![Capture d’écran 2022-12-29 à 11.31.32](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/e/7eb622932daf737511158854c4411081f59ca8a3.jpeg)  
Edit: Forgot to mention that Yuka always begins the same (in the top left corner). It could at least alternate between corners to make it a bit more varied (at least, visually 😉
