Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

Snack Break Problem #22

Last Challenge

Last challenge was to re-create the game "SUPERHOT", and we had a total of 4 people submit their creations, in order of the first to submit to the last:

I had an extreme amount of trouble trying to decide who should win, therefor, everybody is a winner! All 4 winners shall get the snack break tag for a week. Good luck on the next snack break!

~ shayner32


This week's challenge

I'm excited for this challenge! This is a fun, simple problem that can be applied to many things. In short, this challenge is to make a winning move in a game of Tic Tac Toe. As an example:

local function ReturnMove(board, side)
    --// Code should return:
    return [[
        x_o
        _xo
        o_x
    ]]
end

ReturnMove(
    [[
        x_o
        _xo
        o__
    ]], 
    "x"
)

If the side parameter is o, then you would go in the same place but with an o.

You can be assured that there will always be a winning move for your code. You can make it so if there isn't a winning move the function returns false, or a random move if you wish.

Advanced Challenge

For anyone who can make the best move for a board without a direct winning move will get a special shoutout on the next snack break. This means that the algorithm would never lose in a regular game of tic-tac-toe. The computer would play perfect. You can do anything so long as it works, but I would personally recommend using the minimax algorithm.


Submission

In order to submit your attempt, simply message me, OldPalHappy, here with the model or place, open sourced. If you would like, you can also message me on discord or via the forum messaging system with a link to your code.

Commentary

Leave a Comment

Perci1 says: February 17, 2017
Aw come on I was working on a really cool submission with enemies and everything but was taking my time because snack breaks are usually a ton of time apart D: rip
OldPalHappy says: February 18, 2017
I think we're trying to keep these weekly for as long as possible now.
TheeDeathCaster says: February 18, 2017
Ok, I sent in a submission! >:D Fyi, the AI isn't the best. XD
superalp1111 says: February 23, 2017
Do we have to make a cool tic-tac-toe game which always wins with GUI animations etc.or a model just to show logic of it?
OldPalHappy says: March 11, 2017
tehee...