Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Is there another way to check dim stored values?

Author
Message
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 15:50
trying to find another way of checking a winning line when I have 9 squares to check.

one win line would be 123 across or 456 or 147.

now the stored value is from 1 to 6, at the moment I am doing this



now that's a lot of typing and when I have 9 winning ways times 6 makes for lot of code.

what the square lands on is placed in stored like so, first number the square the next number check options then the value from 1 to 6.

so any ideas?

Dark Physics makes any hot drink go cold.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 15:55
I'm still not sure what you are wanting, but if you have a large array that needs to be checked by a value:



The fastest code is the code never written.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 16:04 Edited at: 21st Jul 2010 16:12
Hawkblood thank's, one way but the stored array is only nine in size.

123
456
789

that's how the squares are laid out on the screen.
win lines are:-
123 or 456 or 789 or 145 or 258 or 789
and
1245 or 2356 or 4578 or 5689
and
12347 or 12358 or 12369

and so on..
square 1 could have 1-6 stored in it.
sq1=6 sq2=4 sq3=5 would equal no win.

does this help explain.

Dark Physics makes any hot drink go cold.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 16:12
Quote: "does this help."
No. I don't understand what you are trying to do. I am not seeing a pattern in your system....

The fastest code is the code never written.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 21st Jul 2010 16:13
If you are checking a large array then for any point in the array store(x,y) there are 4 winning lines assuming (x,y) is the centre point of those lines: Horizontal, vertical and 2 diagnonals. Something like:



You also need to check you don't go out of bounds ie. checking (0,0) then would try and access (-1,-1)
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 16:24 Edited at: 21st Jul 2010 16:42
winning line are

three in a row or column.-|
four in a corner, top left, top right, bottom left, bottom right.
top row any column down.
middle row any column down.
bottom row any column down.
first column any row across.
second column any row across.
third column any row across.
rotated U meaning first column, bottom row, last column, then rotate.
top and middle row.
middle and bottom row.
first and second column.
second and third column.
X or + shape win.
all nine squares.


as you can see a few to check.

edit
think I have 29 possible way to get a win times 6.



Dark Physics makes any hot drink go cold.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 18:08
Make an array of Wins(29,3,3) as boolean.
Put each of the winning combinations into that array. Do a loop of 29 to see if the player combination matches a winning combo.

The fastest code is the code never written.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 19:00
ok tried this



only thing is it does not re display what I put in.

Dark Physics makes any hot drink go cold.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Jul 2010 19:10 Edited at: 21st Jul 2010 19:20
OK so as a slight change to your code:


Then check using:


HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 19:16
that what I sort of have, was hoping to find a simpler way that did not involve putting in 34 wins if statements with 9 checks in each.

seeing the binary system looks broke will have to try "0010101" version to keep the ninth bit.

Dark Physics makes any hot drink go cold.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Jul 2010 19:21
Well you do have quite a complicated system for winning...

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Jul 2010 19:41 Edited at: 21st Jul 2010 19:45
You could reduce the number of checks as some of these aren't necessary as they contain duplicates... for example why check "111111111" when you know you win with "111000000"?

You can reduce the number of checks to 13 if it's OK to remove those:
EDIT: Ooops, actually you can reduce it to 11!



Then check using:


HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 19:54
cheers baxslash, I expect your dead right on how many checks that are need, but until I see it [in other words all the possible wins in the 11] will be trying the hard way.

came up with this that makes a winning line for each value of 1 to 6



now to make a random winning line maker bit for the above code.

Dark Physics makes any hot drink go cold.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Jul 2010 20:16
right this seem to work, if anyone would like it explianed I'll try.



Dark Physics makes any hot drink go cold.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Jul 2010 03:51
You could use a 1D array for the score instead of a 2D one and just search the arrays index based off a win string, so for example:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.

Login to post a reply

Server time is: 2026-07-25 05:32:46
Your offset time is: 2026-07-25 05:32:46