Jump to content
Zach

RAM Tic-Tac-Toe

Recommended Posts

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.

post-2163-1241939300_thumb.png

RAMtictactoe.bin

Edited by Zach

Share this post


Link to post
Share on other sites

Here are the keypad controls in Stella:

LEFT				  RIGHT
123				   890
qwe				   iop
asd				   kl;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 by Thomas Jentzsch

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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 #255

lp2:

ldy board,x

patch:

cpy #1

beq skip ; fixed

and table,x

beq not_this

skip:

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 toe

That'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 by supercat

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...