IPB

Welcome Guest ( Log In | Register )

2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 
Reply to this topicStart new topic
> Tic-Tac-Toe anyone?, Writen in CCX ^^
Snap
post Apr 14 2009, 04:40 AM
Post #1


The following post is supplementry information
*****

Group: Global Moderators
Posts: 2,922
Joined: 29-January 06
From: Eugene Oregon
Member No.: 31



Tic Tac Toe
Requires Version 1.92+

COMMANDS:
!playttt - You and a friend must type this to start the game.
!move [Position] - A1 B2 C3 etc are examples of valid entries.
!showboard - shows the board.
!clearboard - resets the entire game

Remember, you can modify the access to these commands with !setcc [commandname] [newaccess]

Sorry about the difficult installation - in 2.7 this wont be an issue.
For now you'll have to copy/paste the single lines in.

Enjoy!!


Paste one line at a time
CODE
/testcc Setting common vars. %setvar(TTT_SX,O)%setvar(TTT_SO,X)
/testcc Setting Square values... %setvar(TVL_A3,01100001)%setvar(TVL_B3,00100010)%setvar(TVL_C3,10100100)%setvar(TVL_A2,00010001)
/testcc More square values... %setvar(TVL_B2,11010010)%setvar(TVL_C2,00010100)%setvar(TVL_A1,10001001)%setvar(TVL_B1,00001010)%setvar(TVL_C1,01001100)
/testcc Valid Moves... %listadd(Tval,A1)%listadd(Tval,A2)%listadd(Tval,A3)%listadd(Tval,B1)%listadd(Tval,B2)%listadd(Tval,B3)%listadd(Tval,C1)%listadd(Tval,C2)%listadd(Tval,C3)

/addcc move 10/ %if(%var(TTTon)=false,%die(Need more players))& %if(%var(TTT_PTurn)<>%user,%die(It's %var(TTT_PTurn)'s turn))
/appendcc move & %if(%var(TTT_%rest),%die(Square Ocupied...))& %runcc(toggleturns)& %runcc(showboard)
/appendcc move & %runcc(checkvictory)& %withvar(TTT_P%var(TTT_Turn),+%var(TVL_%rest))& %setvar(TTT_%rest,%var(TTT_Turn))

/addcc showboard 10/ %for(3,1,##|%for(1,3,%showvar(TTT_#A/##,_)|)& )
/addcc clearboard 10/ %for(3,1,%for(1,3,%setvar(TTT_#A/##,)))& %setvar(TTT_PX,0)%setvar(TTT_PO,0)& %setvar(TTT_PlayerX,)%setvar(TTT_PlayerO,)
/appendcc clearboard & %setvar(TTTOn,false)& %if(%1=silent,,Game cleared.)

/addcc checkvictory 10/ %if(%math(%var(TTT_PX)+%var(TTT_PO))=33333333,Cat's Game! %runcc(clearboard))
/appendcc checkvictory & %if(%instr(%var(TTT_P%var(TTT_Turn)),3)<>0,Tic-Tac-Toe 3 in a row! You win %user!%runcc(clearboard,silent))

/addcc playttt 10/ %if(%var(TTT_PlayerX)=%user,%die(You're already playing as X...))%if(%var(TTT_PlayerX),P1 Taken,%di
/appendcc playttt e(%setvar(TTT_PlayerX,%user)%user You'll play as X%setvar(TTT_PTurn,%user)))%if(%var(TTT_PlayerO),
/appendcc playttt P2 Taken,%die(%setvar(TTT_PlayerO,%user)%user You'll play as O%setvar(TTT_PTurnR,%user). Game ready-
/appendcc playttt %var(TTT_PlayerX)[X] type %triggermove [Position] - Like A1 or C3 etc.%setvar(TTTOn,true)))The game is full.

/addcc toggleturns 10 %setvar(TTT_Turn,%var(TTT_S%var(TTT_Turn)))%setvar(TTT_PTurn,%var(TTT_PTurnR))%setvar(TTT_PTurnR,%var(TTT_PTurn))


I Know this looks really complicated in this form - but when using the CCX viewer (Beta only) it doesn't look that bad.


It felt really nice to write this - this was the first thing I ever made work in RaiBot - which was what got me into coding in the first place.- And what also inspired the CCX system. - It's fitting that this would be my first game using CCX.


How the victory check works:

I've assigned a value to each square:
VALUES:
[01,100,001][00,100,010][10,100,100]
[00,010,001][11,010,010][00,010,100]
[10,001,001][00,001,010][01,001,100]
When a player moves to that square that 'value' is added to their 'score'. - Then I simply check if there's a 3 in their score - they've won!
(Not bad for the fact that I came up with this nearly 10 years ago)

I wrote this in CCX in an attempt to break any barriers that would prevent someone from doing something similar - to improve the power of the language.

Have fun!!





QUOTE(First game played)
[12:10:08 AM] <Snap> !playttt
[12:10:08 AM] <SCSF> Snap You'll play as X
[12:10:08 AM] <Snap> type >!playttt
[12:10:13 AM] <Tempt_azn_kid> !okayttt
[12:10:17 AM] <Tempt_azn_kid> !playttt
[12:10:17 AM] <SCSF> Tempt_azn_kid You'll play as O. Game ready- Snap[X] type !move [Position] - Like A1 or C3 etc.
[12:10:29 AM] <Snap> !move A1
[12:10:29 AM] <SCSF> 3|_|_|_|
[12:10:29 AM] <SCSF> 2|_|_|_|
[12:10:29 AM] <SCSF> 1|O|_|_|
[12:10:30 AM] <Tempt_azn_kid> !move a1
[12:10:31 AM] <SCSF> Square Ocupied...
[12:11:00 AM] <Snap> ttt stands for Tic-Tac-Toe incase you weren't catching that :P
[12:11:10 AM] <Snap> try somewhere else?
[12:11:18 AM] <Tempt_azn_kid> ah...
[12:11:18 AM] <Snap> A_B_C
[12:11:28 AM] <Tempt_azn_kid> move 2b
[12:11:31 AM] <Tempt_azn_kid> !move 2b
[12:11:31 AM] <SCSF> Invalid move
[12:11:34 AM] <Snap> b2
[12:11:41 AM] <Tempt_azn_kid> !move b3
[12:11:42 AM] <SCSF> 3|_|X|_|
[12:11:51 AM] <SCSF> 2|_|_|_|
[12:11:51 AM] <Tempt_azn_kid> oops
[12:11:51 AM] <SCSF> 1|O|_|_|
[12:11:51 AM] <Tempt_azn_kid> haha
[12:11:52 AM] <Snap> :P
[12:11:52 AM] <Snap> !move C1
[12:11:52 AM] <SCSF> 3|_|X|_|
[12:11:53 AM] <SCSF> 2|_|_|_|
[12:11:55 AM] <SCSF> 1|O|_|O|
[12:12:12 AM] <Tempt_azn_kid> i lost :(
[12:12:12 AM] <Snap> lol
[12:12:12 AM] <Tempt_azn_kid> !move b1
[12:12:12 AM] <SCSF> 3|_|X|_|
[12:12:13 AM] <SCSF> 2|_|_|_|
[12:12:14 AM] <SCSF> 1|O|X|O|
[12:12:15 AM] <Snap> !move B2
[12:12:17 AM] <SCSF> 3|_|X|_|
[12:12:20 AM] <Tempt_azn_kid> no i didn't
[12:12:21 AM] <SCSF> 2|_|O|_|
[12:12:30 AM] <SCSF> 1|O|X|O|
[12:12:30 AM] <Snap> didn't you?
[12:12:34 AM] <Tempt_azn_kid> watch
[12:12:42 AM] <Tempt_azn_kid> !move c3
[12:12:53 AM] <Snap> try again (I fixed this bug)
[12:12:58 AM] <Tempt_azn_kid> !move 3c
[12:12:58 AM] <SCSF> Invalid move
[12:13:13 AM] <Tempt_azn_kid> !move c3
[12:13:13 AM] <SCSF> 3|_|X|X|
[12:13:13 AM] <SCSF> 2|_|O|_|
[12:13:13 AM] <SCSF> 1|O|X|O|
[12:13:13 AM] <Tempt_azn_kid> oh i did
[12:13:13 AM] <Tempt_azn_kid> dam
[12:13:14 AM] <Snap> !move A3
[12:13:15 AM] <SCSF> 3|O|X|X|
[12:13:15 AM] <Tempt_azn_kid> didn't see that
[12:13:17 AM] <SCSF> 2|_|O|_|
[12:13:26 AM] <SCSF> 1|O|X|O|
[12:13:26 AM] <Tempt_azn_kid> it was cause i pressed the wrong button
[12:13:38 AM] <SCSF> Tic-Tac-Toe 3 in a row! You win Snap!
[12:13:38 AM] <Snap> :)
[12:13:46 AM] <Tempt_azn_kid> you are a nerd 8)
[12:14:01 AM] <Snap> even victory check!
[12:14:01 AM] <Snap> aren't I just like -- awesome
[12:14:03 AM] <Tempt_azn_kid> haha


Update
If you want to try and make it show the board on one line use this:

/editcc showboard 3|%for(1,3,%showvar(TTT_#A3,_)|)%for(1,54, )2|%for(1,3,%showvar(TTT_#A2,_)|)%for(1,57, )1|%for(1,3,%showvar(TTT_#A1,_)|)

Modify those bolded numbers until you have the right offset. (those numbers are the amount of spaces)

:)

This post has been edited by Snap: Apr 22 2009, 11:59 PM


--------------------
~Life is all busy and stuff right now. - Car accident, lots of dr. appointments... Other stuff too. I still <3 StealthBot.net - - I'll be around.
Thinking about PMing me? Post it instead! CCX Forums | SnapNJacks Trivia Forums
IPB Image
IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Be-Eazie
post Apr 21 2009, 08:43 PM
Post #2


Master Of Nothing
***

Group: Beta Testers
Posts: 123
Joined: 1-January 08
Member No.: 32,150



QUOTE
CODE
/testcc Setting common vars. %setvar(TTT_SX,O)%setvar(TTT_SO,X)
/testcc Setting Square values... %setvar(TVL_A3,01100001)%setvar(TVL_B3,00100010)%setvar(TVL_C3,10100100)%setvar(TVL_A2,00010001)
/testcc More square values... %setvar(TVL_B2,11010010)%setvar(TVL_C2,00010100)%setvar(TVL_A1,10001001)%setvar(TVL_B1,00001010)%setvar(TVL_C1,01001100)
/testcc Valid Moves... %listadd(Tval,A1)%listadd(Tval,A2)%listadd(Tval,A3)%listadd(Tval,B1)%listadd(Tval,B2)%listadd(Tval,B3)%listadd(Tval,C1)%listadd(Tval,C2)%listadd(Tval,C3)

/addcc move 10/ %if(%var(TTTon)=false,%die(Need more players))& %if(%var(TTT_PTurn)<>%user,%die(It's %var(TTT_PTurn)'s turn))
/appendcc move & %if(%var(TTT_%rest),%die(Square Ocupied...))& %runcc(toggleturns)& %runcc(showboard)
/appendcc move & %runcc(checkvictory)& %withvar(TTT_P%var(TTT_Turn),+%var(TVL_%rest))& %setvar(TTT_%rest,%var(TTT_Turn))

/addcc showboard 10/ %for(3,1,##|%for(1,3,%showvar(TTT_#A/##,_)|)& )
/addcc clearboard 10/ %for(3,1,%for(1,3,%setvar(TTT_#A/##,)))& %setvar(TTT_PX,0)%setvar(TTT_PO,0)& %setvar(TTT_PlayerX,)%setvar(TTT_PlayerO,)
/appendcc clearboard & %setvar(TTTOn,false)& %if(%1=silent,,Game cleared.)

/addcc checkvictory 10/ %if(%math(%var(TTT_PX)+%var(TTT_PO))=33333333,Cat's Game! %runcc(clearboard))
/appendcc checkvictory & %if(%instr(%var(TTT_P%var(TTT_Turn)),3)<>0,Tic-Tac-Toe 3 in a row! You win %user!%runcc(clearboard,silent))

/addcc playttt 10/ %if(%var(TTT_PlayerX)=%user,%die(You're already playing as X...))%if(%var(TTT_PlayerX),P1 Taken,%di
/appendcc playttt e(%setvar(TTT_PlayerX,%user)%user You'll play as X%setvar(TTT_PTurn,%user)))%if(%var(TTT_PlayerO),
/appencc playttt P2 Taken,%die(%setvar(TTT_PlayerO,%user)%user You'll play as O%setvar(TTT_PTurnR,%user). Game ready-
/appendcc playttt %var(TTT_PlayerX)[X] type %triggermove [Position] - Like A1 or C3 etc.%setvar(TTTOn,true)))The game is full.


I coudnt seem to get this to work. I did notice 2 typos I changed them and still wasnt successfull, could u give it another loook see if u see any more mistakes and possibly edit original post to fix errors.. thx


--------------------
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Snap
post Apr 23 2009, 12:01 AM
Post #3


The following post is supplementry information
*****

Group: Global Moderators
Posts: 2,922
Joined: 29-January 06
From: Eugene Oregon
Member No.: 31



I pasted those commands after successfully testing the game.
Could you paste what you're getting when trying to play the game? - And you are using 1.92 + right?

What typo's?
Edit; found one "appencc" - well thanks for being my guinea pig. We'll get this working.

Update: I had forgotten the toggleturns command apparently. - Add that cc, and try again.


--------------------
~Life is all busy and stuff right now. - Car accident, lots of dr. appointments... Other stuff too. I still <3 StealthBot.net - - I'll be around.
Thinking about PMing me? Post it instead! CCX Forums | SnapNJacks Trivia Forums
IPB Image
IPB Image
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 17th November 2019 - 02:04 AM
Skin by Andrea
Website Legal Information | Hosted by LunarPages