r/Tf2Scripts • u/prolvlwhale • Aug 02 '22
Script Another program: Tic Tac Toe
Another program from me, a little simpler this time. This is a simple 2-player tic-tac-toe program. I was going to make a perfect AI for it but I went a little crazy during it so I'm taking a break. I wanted to release this version, since it is functional.
I also made a very basic syntax highlighting file for sublime text if anyone wants it: https://pastebin.com/erSCCRBx
I am quickly running out of ideas to make, so I'll probably take a break from source coding until I come up with something good, or someone suggests something.
8
Upvotes
View all comments
Show parent comment
2
u/prolvlwhale Aug 02 '22
It looks differently done than yours; I assigned each space alias some functions and a state that calls either X, O, or ~ (for empty). From there, it is pretty simple to make the program. For example, when I check if a space is valid for input, I bind the X and O aliases to the warning for invalid input, and the ~ alias to the valid input alias, placing the square. For win testing, I unbind the enemy's state alias and the empty state alias and bind the current player's state alias to move to the next square in the row. This means I can use fewer lines of code, and it makes the code more readable. There might be some more optimizations I could do for this with pointers, but I didn't think of them at the time. Something for v2.0, I guess. For the tie detection, I used a simple cycle counter like on the wiki.