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.

AppGameKit Classic Chat / Mastermind Algorthym wont work

Author
Message
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Jan 2015 08:10 Edited at: 12th Apr 2018 20:56
Below is a snippet of my algorythm for working out the black and white pieces on a mastermind board. Spritenum holds the difficulty selected. wCount white markers bCount black markers.

now if i use the test data
1,2,3,4 for the 4 correct solutions
1,5,5,1 shows 1 black 1 white
1,2,5,5 shows 2 black as it should
3,3,6,6 shows 1 white
1,1,1,1 shows 1 black 1 white

I dont beleive the exit is working any help would be greatly appreciated



</div>
fubar
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 22nd Jan 2015 09:28
Your basic idea is fine (I used to write Mastermind games on a TI-57 programmable calculator in my youth ......).

I think the problem is you do not set flag[slot] to used when you get a black counter. So, in your 1,5,5,1 example, when it does the fourth digit (the second 1) the for loop in the else clause picks up the first 1 (flag[1]) as a white match because it has never been marked 'used'.

I would be inclined to simplify it by having 2 loops - one that tests for blacks then one that tests for whites
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Jan 2015 13:05
Thanks thats it all fixed now Paulrobson thanks for your help

fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 22nd Jan 2015 13:21 Edited at: 12th Apr 2018 20:56
Well i thought i fixed it till i supplied the following test data
answer 1,2,3,4
test data
1,1,1,1 black 1 no white
2,2,2,2 black 1 white 1
3,3,3,3 black 1 white 1



but all original test data worked

</div>
fubar
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 23rd Jan 2015 15:40 Edited at: 23rd Jan 2015 15:41
You need to flag both the target pegs and the guesses so that you can discount both from the checks.

Below is a complete mastermind game. There is no user input, just random guesses that continue whilst you click the mouse but the checkGuess() function should be all you need.



AGK V2 user - Tier 1 & 2

Login to post a reply

Server time is: 2024-11-25 17:47:55
Your offset time is: 2024-11-25 17:47:55