-
Notifications
You must be signed in to change notification settings - Fork 1
[RFR] Minimax algorithm return a valid solution #12
base: master
Are you sure you want to change the base?
Conversation
src/quarto/ai/basic.go
Outdated
return piecesListNonWinning.([]int) | ||
} | ||
return loosingBoxList.([]grid.Point) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have a rule in vscode to add automatically an empty line at the end of each file.
node.Childs = append(node.Childs, AppendChildNodes(childNode, depth-1, quit)) | ||
} else { | ||
for i := 0; i < len(boxList); i++ { | ||
if len(piecesList) > 1 && len(boxList) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should split the code into small functions because it's not so readable. And in addition you could test small part of code.
src/quarto/game/game.go
Outdated
// PlayTurn return the next move for given grid | ||
func PlayTurn(currentState state.State) state.State { | ||
newState, done := ai.StartMiniMax(currentState, 0) | ||
newState, done := ai.StartMiniMax(currentState, 30) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have a constant
return bestState | ||
} | ||
|
||
func CalculateNodeValue(node StateNode) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this function but I don't find a prettier version ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the same ...
src/quarto/ai/minimax.go
Outdated
childNode.Value = LoosingLeafValue | ||
} | ||
return append(currentNode.Childs, childNode) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need else
https://trello.com/c/ty1OGS7T
Full algorithm is done
I have not won against computer since this. (draws sometimes)