Zach Posted May 10, 2009 Share Posted May 10, 2009 (edited) It's not much, but it's enough to join the club. It's a two player game using keypad controllers. You can use reset to clear the board. To launch Stella so that it emulates keypad input, use "Stella -bc Keyboard RAMtictactoe.bin" I was hoping to fit in some logic to automatically check for three-in-a-row, but that won't happen for a while, if ever. RAMtictactoe.bin Edited May 10, 2009 by Zach Quote Link to comment Share on other sites More sharing options...
Zach Posted May 10, 2009 Author Share Posted May 10, 2009 Here are the keypad controls in Stella: LEFT RIGHT 123 890 qwe iop asd kl; Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted May 10, 2009 Share Posted May 10, 2009 Cool! You should enter this into the PDRoms competition! Quote Link to comment Share on other sites More sharing options...
Zach Posted May 11, 2009 Author Share Posted May 11, 2009 I got sound working, and changed the colors. There are now 8 bytes to spare, though I'm not sure what to do with them. The most compact code I've come up with for checking for three-in-a-row is over 40 bytes. RAMtictactoe_11May09.zip Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted May 11, 2009 Share Posted May 11, 2009 (edited) The most compact code I've come up with for checking for three-in-a-row is over 40 bytes. Hmm, 40 bytes sounds like a lot to me. If nothing helps, maybe storing the board data differently would do. E.g. you could add a 4th column (2 extra bytes would do here, the last one could be share with code) and then check for one of the following 4 pattern: 111 (horizontal) 1xxx1xxx1 (vertical) 1xxxx1xxxx1, 1xx1xx1 (diagonals) So you have to find three 1s (X or O), with a gap of 0, 2, 3 and 4. Or you could initially block all 8 possible rows (initial value = 3) and whenever a square is set, decrease the value for all rows this square belongs to. When 0 is reached, you have three in a row. Alternatively you could start with an initial value of 0 and check for +3 and -3. I am sure there are even more possible algorithms, you "just" have to find out the most space efficient one. EDIT: Just tried to code something myself and came out with 41 bytes. Ouch! Edited May 11, 2009 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
+batari Posted May 11, 2009 Share Posted May 11, 2009 I tried this out, and only set the left controller to keyboard while the other was set to joystick, and found that I had a CPU opponent. The "AI" was not great, but not bad for an accident. Quote Link to comment Share on other sites More sharing options...
supercat Posted May 18, 2009 Share Posted May 18, 2009 (edited) EDIT: Just tried to code something myself and came out with 41 bytes. Ouch! It's tough, isn't it. I've shrunk it a little, though how much depends upon how the board is stored. lp1: ldx #8 lda #255lp2: ldy board,xpatch: cpy #1 beq skip ; fixed and table,x beq not_thisskip: dex bpl lp2 ; Got tic tac toe not_this: asl patch+1 bcc lp1 rol patch+1 ; If we get here there's no tic tac toeThat's 23 bytes, plus nine for a table, or 32 total. A "tic tac toe" will be three 1's, 2's, 4's, 8's, etc. in a row. Edited May 19, 2009 by supercat Quote Link to comment Share on other sites More sharing options...
Zach Posted May 19, 2009 Author Share Posted May 19, 2009 Nice, John! And I was pleased just for getting under 40 bytes, not counting the table. It'll take me a while to figure out your code works. Quote Link to comment Share on other sites More sharing options...
supercat Posted May 19, 2009 Share Posted May 19, 2009 Nice, John! And I was pleased just for getting under 40 bytes, not counting the table. It'll take me a while to figure out your code works. I suppose it might help if I give the table. The values for each square should be: 01101101 01110111 01111010 10101111 10110100 10111011 11001110 11010111 11011001 Looking at the code, I erred on some of the logic (fixed, I hope). The basic idea is that there are eight possible tictactoes for X, likewise for O. Any square which is not "X" will disqualify some of the tictactoes for X, and a square that is not "O" will disqualify some for O. The loop will run through to see if there's any tic tac toe for squares with a value of 1, then 2, then 4, then 8, etc. It's two instructions shorter to let the loop run for all powers of two than to just run it for values of 1 and 2. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.