|
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
|
06-21-2009 12:08
Hello, everyone.
I've recently scripted Tic-Tac-Toe as a minigame for one of my systems, but I've run into a problem with the Win Detection Algorithm.
Currently, it's converting the game board into a string of 1s and 0s to compare against a list of win scenarios.
list WinSituations = ["111000000", "000111000", "000000111", "100100100", "010010010", "001001001", "100010001", "001010100"];
Now, let's say you have this as the game board:
XXX OOO OXO
The converted game board for Xs would come out as "010000111." The last three 1s indicate a straight line in the top row, which is also shown in the list of Win Situations. However, because of the outlier in the bottom row, it is not being detected as a win.
Any help is appreciated... Thanks in advance.
_____________________
Life is a highway... And I just missed my exit.
|
|
Cerise Sorbet
Registered User
Join date: 8 Jun 2008
Posts: 254
|
06-21-2009 12:19
Hi Cypher. Can you turn the binary strings into real integers? & can work if it is that way.
|
|
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
|
06-21-2009 12:23
I could, but it's easier with string because I can just tack a character onto the end. Example: integer int = 1; int += 1; (int == 2) string str = "1"; str += "1"; (str == "11"  Even if I did use integers, the problem would still arise.
_____________________
Life is a highway... And I just missed my exit.
|
|
Cerise Sorbet
Registered User
Join date: 8 Jun 2008
Posts: 254
|
06-21-2009 12:38
If there are integers then you can have AND comparison on a loop. Then you do not have an equality test.
|
|
Cerise Sorbet
Registered User
Join date: 8 Jun 2008
Posts: 254
|
06-21-2009 13:21
// This is dummy tic tac toe. You win when you make a row. It does not play against you.
// I have a stack of prims all linked and these are the names. list prims = ["topleft", "top", "topright", "left", "center", "right", "bottomleft", "bottom", "bottomright"];
// These are the numbers that win. list wins = [0x1C0, 0x038, 0x007, 0x124, 0x092, 0x049, 0x111, 0x054];
// The prims touched go in here. integer pressed = 0;
default { state_entry() { integer x; for (x = 1; x <= 9; ++x) { llSetLinkPrimitiveParams(x, [PRIM_COLOR, ALL_SIDES, < 1.0, 1.0, 1.0>, 1.0]); } }
touch_start(integer total_number) { integer link = llDetectedLinkNumber(0); string linkname = llGetLinkName(link); integer found = llListFindList(prims, [linkname]); if (found >= 0) { llSetLinkPrimitiveParams(link, [PRIM_COLOR, ALL_SIDES, < 1.0, 0.0, 0.0>, 1.0]); llOwnerSay(linkname); pressed = pressed | (1 << found); // | so it does not add }
integer x; for (x = llGetListLength(wins) - 1; x >= 0; --x) { if ((pressed & llList2Integer(wins, x)) == llList2Integer(wins, x)) { llOwnerSay("win"); llResetScript(); } } } }
|
|
Cypher Ragu
[Mad Scientist]
Join date: 6 Jul 2008
Posts: 174
|
06-21-2009 17:30
Interesting. Thanks for the example.
_____________________
Life is a highway... And I just missed my exit.
|