haskell-ex icon indicating copy to clipboard operation
haskell-ex copied to clipboard

Solved TicTacToe

Open borboss366 opened this issue 8 years ago • 4 comments

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

borboss366 avatar Jan 03 '17 19:01 borboss366

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

neongreen avatar Jan 04 '17 20:01 neongreen

Refactored the code. Still solves the first move for tic tac toe slowly.

borboss366 avatar Jan 16 '17 12:01 borboss366

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.

neongreen avatar Jan 21 '17 00:01 neongreen

And it's hard to give more advice about the code because I don't understand it :)

neongreen avatar Jan 21 '17 00:01 neongreen