Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-28-2010, 05:01 PM   #1
Blkhwks19
Member
 
Join Date: Oct 2006
Posts: 85
Default [AS3] help creating solution check algorithm for puzzle type game

Anyone have any idea how to program the algorithm for that old game Mastermind? The users guess needs to be checked against the solution (each consisting of 4 colors). The user is notified how many colors they have correct and in the correct position, and how many colors they have correct, but in the wrong position. Since duplicates are allowed in the solution, I cant simply check the solutions colors with the matching position of the guess. I need something a little better that can handle the duplicates and im not quite sure how to set that up. Any thoughts or ideas on this?
Blkhwks19 is offline   Reply With Quote
Old 06-28-2010, 08:56 PM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

First you check for black matches, then white matches using only those positions that didn't get a black match.

Checking for black matches is simple. If position i in the guess matches position i in the code, it's a match. Then eliminate i from the list of positions that will be used for checking white matches.

Then, for each colour of peg, count the number of pegs of that colour in the guess, and in the code. (using only the positions that haven't been eliminated in the previous step) For each colour, pick the smaller count of either the guess or of the code, and add them all up. That will be the number of white matches.

Does this make sense?
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:24 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.