options: #You don't need to change them# Ai-block: Red Wool Player-block: Green Wool Draw-block: Yellow Wool #Background block# Background: blue glass pane #Sounds https://www.digminecraft.com/lists/sound_list_pc.php# Win-sound: block.anvil.destroy Lose-sound: entity.player.levelup Draw-sound: block.note_block.bass #code you are free to read or copy or to change# on load: set {xo.1} to 12 set {xo.2} to 13 set {xo.3} to 14 set {xo.4} to 21 set {xo.5} to 22 set {xo.6} to 23 set {xo.7} to 30 set {xo.8} to 31 set {xo.9} to 32 function game(p: player): set {_gui} to a new chest inventory with 6 row with name "&a&lT&1i&5c &e&lT&9a&ec &b&lT&6&lo&ce" set slot 8 of {_gui} to Barrier named "&e&lSettings" with lore "&7" and "&7- Left click to reset" and "&7- Right click to close" set slot 0 of {_gui} to Lime Stained Glass Pane named "&a&lEasy" with lore "&7" and "&7The AI play with random algorithm" and "&7It's so easy to win at" and "&7" and "&7Mode: &cOff" set slot 9 of {_gui} to Orange Stained Glass Pane named "&6&lMedium" with lore "&7" and "&7The AI play with thinking about next move algorithm" and "&7It's medium difficulty but you can win" and "&7" and "&7Mode: &cOff" set slot 18 of {_gui} to Red Stained Glass Pane named "&4&lHard" with lore "&7" and "&7The AI play with minimax" and "&7It's imposable to win" and "&7" and "&7Mode: &cOff" set {_co1} to 1 set {_co2} to 1 set {_co3} to 1 if {xo.count.ai.%{_p}%} is greater than 1: set {_co1} to {xo.count.ai.%{_p}%} if {xo.count.draw.%{_p}%} is greater than 1: set {_co2} to {xo.count.draw.%{_p}%} if {xo.count.player.%{_p}%} is greater than 1: set {_co3} to {xo.count.player.%{_p}%} set slot 53 of {_gui} to {_co1} of {@Ai-block} named "&c&lAI" with lore "&7AI won &6&l%{xo.count.ai.%{_p}%}%&7/&6&l%{xo.count.ai.%{_p}%}+{xo.count.player.%{_p}%}+ {xo.count.draw.%{_p}%}% &7times" set slot 49 of {_gui} to {_co2} of {@Draw-block} named "&6&lDraw" with lore "&7You won &6&l%{xo.count.draw.%{_p}%}%&7/&6&l%{xo.count.ai.%{_p}%}+{xo.count.player.%{_p}%}+ {xo.count.draw.%{_p}%}% &7times" set slot 45 of {_gui} to {_co3} of {@Player-block} named "&a&lYou" with lore "&7You won &6&l%{xo.count.player.%{_p}%}%&7/&6&l%{xo.count.ai.%{_p}%}+{xo.count.player.%{_p}%}+ {xo.count.draw.%{_p}%}% &7times" set slots (all integers between 12 and 14) of {_gui} to {@Background} named "&cEmpty" with lore "&7" and "&7Click to fill" set slots (all integers between 21 and 23) of {_gui} to {@Background} named "&cEmpty" with lore "&7" and "&7Click to fill" set slots (all integers between 30 and 32) of {_gui} to {@Background} named "&cEmpty" with lore "&7" and "&7Click to fill" if {xo.dif.%{_p}%} is 1: set slot 0 of {_gui} to Lime Stained Glass Pane of unbreaking 3 with enchants flag hidden named "&a&lEasy" with lore "&7" and "&7The AI play with random algorithm" and "&7It's so easy to win at" and "&7" and "&7Mode: &aOn" if {xo.dif.%{_p}%} is 2: set slot 9 of {_gui} to Orange Stained Glass Pane of unbreaking 3 with enchants flag hidden named "&6&lMedium" with lore "&7" and "&7The AI play with thinking about next move algorithm" and "&7It's medium difficulty but you can win" and "&7" and "&7Mode: &aOn" if {xo.dif.%{_p}%} is 3: set slot 18 of {_gui} to Red Stained Glass Pane of unbreaking 3 with enchants flag hidden named "&4&lHard" with lore "&7" and "&7The AI play with minimax" and "&7It's imposable to win" and "&7" and "&7Mode: &aOn" set {_loop} to 0 loop 41 times: if {xo.place.%{_loop}%.%{_p}%} is false: set slot {xo.%{_loop}%} of {_gui} to {@Ai-block} named "&cAI" add 1 to {_loop} set {_loop} to 0 loop 41 times: if {xo.place.%{_loop}%.%{_p}%} is true: set slot {xo.%{_loop}%} of {_gui} to {@Player-block} named "&aYOU" add 1 to {_loop} open {_gui} to {_p} function winlose(p: player): set {_loop} to 0 loop 10 times: set {xo.place.%{_loop}%.%{_p}%} to "reload" add 1 to {_loop} if {winner.%{_p}%} is "AI": add 1 to {xo.count.ai.%{_p}%} play sound "{@Lose-sound}" with volume 100 with pitch 2 at {_p} for {_p} if {winner.%{_p}%} is "player": add 1 to {xo.count.player.%{_p}%} play sound "{@Win-sound}" with volume 100 with pitch 0.5 at {_p} for {_p} if {winner.%{_p}%} is "draw": add 1 to {xo.count.draw.%{_p}%} play sound "{@Draw-sound}" with volume 100 with pitch 2 at {_p} for {_p} wait 2 second delete {xorochance.%{_p}%} set {_loop} to 0 loop 10 times: delete {xo.place.%{_loop}%.%{_p}%} add 1 to {_loop} set {xorochance.%{_p}%} to "x" chance of 50%: set {xorochance.%{_p}%} to "o" if {xorochance.%{_p}%} is "o": if {xo.dif.%{_p}%} is 3: set {xo.place.5.% {_p}%} to false game({_p}) stop set {_num} to random integer between 1 and 9 set {xo.place.%{_num}%.% {_p}%} to false game({_p}) function aieasy(p: player): loop 20 times: set {_num} to random integer between 1 and 9 if {xo.place.%{_num}%.%{_p}%} is not set: set {xo.place.%{_num}%.%{_p}%} to false stop function aimedium(p: player): set {_num} to random integer between 1 and 6 if {_num} is 1 or 5: aihard({_p}) stop if {_num} is 2 or 3 or 4 or 6: aieasy({_p}) stop function aihard(p: player): if {xo.place.5.%{_p}%} is not set: set {xo.place.5.%{_p}%} to false stop set {_loop} to 1 loop 9 times: if {xo.place.%{_loop}%.%{_p}%} is not set: if {xo.place.%{_loop}-1%.%{_p}%} is false: if {xo.place.%{_loop}-2%.%{_p}%} is false: if {_loop} is not 1 or 5 or 8: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+1%.%{_p}%} is false: if {_loop} is 2 or 5 or 8: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+1%.%{_p}%} is false: if {xo.place.%{_loop}+2%.%{_p}%} is false: if {_loop} is not 3 or 6 or 9: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+3%.%{_p}%} is false: if {xo.place.%{_loop}+6%.%{_p}%} is false: if {_loop} is not 3 or 6 or 9: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+3%.%{_p}%} is false: if {xo.place.%{_loop}-3%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}-3%.%{_p}%} is false: if {xo.place.%{_loop}-6%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 9: if {xo.place.%{_loop}-4%.%{_p}%} is false: if {xo.place.%{_loop}-8%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 7: if {xo.place.%{_loop}-2%.%{_p}%} is false: if {xo.place.%{_loop}-5%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 1: if {xo.place.%{_loop}+4%.%{_p}%} is false: if {xo.place.%{_loop}+8%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 3: if {xo.place.%{_loop}+2%.%{_p}%} is false: if {xo.place.%{_loop}+5%.%{_p}%} is false: set {xo.place.%{_loop}%.%{_p}%} to false stop add 1 to {_loop} set {_loop} to 1 loop 9 times: if {xo.place.%{_loop}%.%{_p}%} is not set: if {xo.place.%{_loop}-1%.%{_p}%} is true: if {xo.place.%{_loop}-2%.%{_p}%} is true: if {_loop} is not 1 or 5 or 8: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+1%.%{_p}%} is true: if {_loop} is 2 or 5 or 8: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+1%.%{_p}%} is true: if {xo.place.%{_loop}+2%.%{_p}%} is true: if {_loop} is not 3 or 6 or 9: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+3%.%{_p}%} is true: if {xo.place.%{_loop}+6%.%{_p}%} is true: if {_loop} is not 3 or 6 or 9: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}+3%.%{_p}%} is true: if {xo.place.%{_loop}-3%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop if {xo.place.%{_loop}-3%.%{_p}%} is true: if {xo.place.%{_loop}-6%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 9: if {xo.place.%{_loop}-4%.%{_p}%} is true: if {xo.place.%{_loop}-8%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 7: if {xo.place.%{_loop}-2%.%{_p}%} is true: if {xo.place.%{_loop}-5%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 1: if {xo.place.%{_loop}+4%.%{_p}%} is true: if {xo.place.%{_loop}+8%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop if {_loop} is 3: if {xo.place.%{_loop}+2%.%{_p}%} is true: if {xo.place.%{_loop}+5%.%{_p}%} is true: set {xo.place.%{_loop}%.%{_p}%} to false stop add 1 to {_loop} if {xo.place.1.%{_p}%} is true: if {xo.place.9.%{_p}%} is true: if {xo.place.2.%{_p}%} is not set: set {xo.place.2.%{_p}%} to false stop if {xo.place.4.%{_p}%} is not set: set {xo.place.4.%{_p}%} to false stop if {xo.place.9.%{_p}%} is true: if {xo.place.1.%{_p}%} is true: if {xo.place.2.%{_p}%} is not set: set {xo.place.2.%{_p}%} to false stop if {xo.place.4.%{_p}%} is not set: set {xo.place.4.%{_p}%} to false stop if {xo.place.3.%{_p}%} is true: if {xo.place.7.%{_p}%} is true: if {xo.place.2.%{_p}%} is not set: set {xo.place.2.%{_p}%} to false stop if {xo.place.6.%{_p}%} is not set: set {xo.place.6.%{_p}%} to false stop if {xo.place.3.%{_p}%} is true: if {xo.place.7.%{_p}%} is true: if {xo.place.2.%{_p}%} is not set: set {xo.place.2.%{_p}%} to false stop if {xo.place.6.%{_p}%} is not set: set {xo.place.6.%{_p}%} to false stop if {xo.place.1.%{_p}%} is not set: set {xo.place.1.%{_p}%} to false stop if {xo.place.3.%{_p}%} is not set: set {xo.place.3.%{_p}%} to false stop if {xo.place.7.%{_p}%} is not set: set {xo.place.7.%{_p}%} to false stop if {xo.place.9.%{_p}%} is not set: set {xo.place.9.%{_p}%} to false stop aieasy({_p}) function reset(p: player): set {xo.count.ai.%{_p}%} to 0 set {xo.count.player.%{_p}%} to 0 set {xo.count.draw.%{_p}%} to 0 delete {xorochance.%{_p}%} set {_loop} to 0 loop 10 times: delete {xo.place.%{_loop}%.%{_p}%} add 1 to {_loop} set {xorochance.%{_p}%} to "o" chance of 70%: set {xorochance.%{_p}%} to "x" if {xorochance.%{_p}%} is "o": if {xo.dif.%{_p}%} is 3: set {xo.place.5.% {_p}%} to false game({_p}) stop set {_num} to random integer between 1 and 9 set {xo.place.%{_num}%.% {_p}%} to false game({_p}) function check(p: player): set {_check} to true loop 2 times: if {_check} is true: set {winner.%{_p}%} to "player" if {_check} is false: set {winner.%{_p}%} to "AI" if {xo.place.1.%{_p}%} is {_check}: if {xo.place.2.%{_p}%} is {_check}: if {xo.place.3.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.4.%{_p}%} is {_check}: if {xo.place.5.%{_p}%} is {_check}: if {xo.place.6.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.7.%{_p}%} is {_check}: if {xo.place.8.%{_p}%} is {_check}: if {xo.place.9.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.1.%{_p}%} is {_check}: if {xo.place.4.%{_p}%} is {_check}: if {xo.place.7.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.2.%{_p}%} is {_check}: if {xo.place.5.%{_p}%} is {_check}: if {xo.place.8.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.3.%{_p}%} is {_check}: if {xo.place.6.%{_p}%} is {_check}: if {xo.place.9.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.1.%{_p}%} is {_check}: if {xo.place.5.%{_p}%} is {_check}: if {xo.place.9.%{_p}%} is {_check}: winlose({_p}) stop if {xo.place.3.%{_p}%} is {_check}: if {xo.place.5.%{_p}%} is {_check}: if {xo.place.7.%{_p}%} is {_check}: winlose({_p}) stop set {_check} to false if {xo.place.1.%{_p}%} is set: if {xo.place.2.%{_p}%} is set: if {xo.place.3.%{_p}%} is set: if {xo.place.4.%{_p}%} is set: if {xo.place.5.%{_p}%} is set: if {xo.place.6.%{_p}%} is set: if {xo.place.7.%{_p}%} is set: if {xo.place.8.%{_p}%} is set: if {xo.place.9.%{_p}%} is set: set {winner.%{_p}%} to "draw" winlose({_p}) stop command /tictactoe []: aliases: ttt trigger: delete {xorochance.%player%} set {_loop} to 0 loop 10 times: delete {xo.place.%{_loop}%.%player%} add 1 to {_loop} set {xorochance.%player%} to "x" chance of 50%: set {xorochance.%player%} to "o" if {xorochance.%player%} is "o": set {_num} to random integer between 1 and 9 set {xo.place.%{_num}%.%player%} to false set {xo.count.ai.%player%} to 0 set {xo.count.player.%player%} to 0 set {xo.count.draw.%player%} to 0 set {xo.dif.%player%} to 1 game(player) stop on inventory click: if name of event-inventory is "&a&lT&1i&5c &e&lT&9a&ec &b&lT&6&lo&ce" : cancel event set {_loop} to 0 loop 9 times: add 1 to {_loop} clicked slot is {xo.%{_loop}%}: if {xo.place.%{_loop}%.%player%} is not set: set {xo.place.%{_loop}%.%player%} to true play sound "block.note_block.bit" with volume 100 with pitch 0.5 at player for player if {xo.dif.%player%} is 1: aieasy(player) stop if {xo.dif.%player%} is 2: aimedium(player) stop if {xo.dif.%player%} is 3: aihard(player) stop clicked slot is 0: set {xo.dif.%player%} to 1 clicked slot is 9: set {xo.dif.%player%} to 2 clicked slot is 18: set {xo.dif.%player%} to 3 clicked slot is 0 or 9 or 18: reset(player) clicked slot is 8: if "%click type%" contains "LEFT": reset(player) if "%click type%" contains "RIGHT": wait 10 tick close player's inventory on inventory click: if name of event-inventory is "&a&lT&1i&5c &e&lT&9a&ec &b&lT&6&lo&ce" : cancel event wait 1.4 tick game(player) check(player)