haskell-ex
                                
                                 haskell-ex copied to clipboard
                                
                                    haskell-ex copied to clipboard
                            
                            
                            
                        Solved TicTacToe
I solved TicTacToe. The simplest version - the computer makes the move into the next empty place.
- [ ] make random computer moves
- [x] make minimax computer moves
- [x] refactor TTTPlay, place the matrix of the cells in the TTTPlay, so I won't need to iterate through all moves to generate the screenshot of the field
- [ ] highlight the winning line
I kinda feel like the whole section
-- from this
isConfigPositionSat :: TTTConfig -> TTTPosition -> Bool
-- till this
calcWinningRow :: TTTPlay -> (TTTPlay -> [TTTRow]) -> Maybe (TTTRow, TTTWinner)
could be improved/rewritten, because currently it's not very comprehensible – but I'm not sure, how
Refactored the code. Still solves the first move for tic tac toe slowly.
Your minimax is slow because it's executed lots of times on the same input. For the same reason a naive implementation of fib is slow:
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
You can look at my solution to see how to use memoisation to improve minimax, or you can implement your own by e.g. storing inputs and outputs in a Map.
And it's hard to give more advice about the code because I don't understand it :)