Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums [AS3] help creating solution check algorithm for puzzle type game
 User Name Remember Me? Password
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 06-28-2010, 05:01 PM #1 Blkhwks19 Member   Join Date: Oct 2006 Posts: 85 [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?
 06-28-2010, 08:56 PM #2 rrh throw a trace() in there   Join Date: Dec 2006 Posts: 1,982 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?

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 03:19 AM.

///

## Categories

Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger