Skip to content

Instantly share code, notes, and snippets.

@miawgogo
Created November 14, 2017 16:06
Show Gist options
  • Save miawgogo/61f3742c360c104bac19023b38270421 to your computer and use it in GitHub Desktop.
Save miawgogo/61f3742c360c104bac19023b38270421 to your computer and use it in GitHub Desktop.
Mastermind
while ((BLACKPEGS(workingCandidate.score) < PEGS) && currentListOfCandidates.indexOfLastEntryAdded >= 0) {
/////your code here
//If (working candidate is not infeasible)
//Generate all 1-step offspring and add to openList
/// loop through pegs
printf("Run");
for(int i = 0; i<4; i++){
/// save old val
int oldval = workingCandidate.variableValues[i];
/// loop throgugh colours
for(int c=0; c<4; c++ ){
/// if colour is not old val
if(c!=oldval) {
int seen;
/// put colour in peg position
ChangeColourOfPegParam1_ToParam2(i, c);
/// if colour not seen before candidate
seen = GetIndexOfWorkingCandidateInThisList(currentListOfCandidates);
/// put at the end of the open list
if(seen==NOTFOUND){
seen = GetIndexOfWorkingCandidateInThisList(listOfExaminedCandidates);
if(seen==NOTFOUND){
AddWorkingCandidateToCurrentList();
}
}
}
}
}
//Move working candidate to closedList
AddWorkingCandidateToExaminedList();
//Move first item in openList into working candidate
CopySolutionFromCurrentListIntoWorkingCandidate(0);
RemoveSolutionFromCurrentList(0);
//Test (working candidate)
ScoreThisTry();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment