[Haskell-beginners] A good data structure for representing a tic-tac-toe board?

KC kc1956 at gmail.com
Wed Mar 20 04:36:26 CET 2013


You may want more than one data structure.
For example, one for machine use and another for display to the user.

Since your data structure is "relatively" small, lists should be fast
enough and strings are lists.


On Mon, Mar 18, 2013 at 8:54 AM, Costello, Roger L. <costello at mitre.org> wrote:
> Hi Folks,
>
> Currently I am representing a tic-tac-toe board as a string, with 'X' denoting player 1 and 'O' denoting player 2. For example, I represent this 2x2 game board:
>
>      'X'        |
> -----------------------
>         |   'O'
>
> with this string: "X  O"
>
> The nice thing about that representation is that it is each to identify which cells are filled or empty, and it is easy to mark a cell with an 'X' or 'O'.
>
> The problem with the representation is that it is difficult to determine when a player has won.
>
> Can you recommend a representation that makes it easy to:
>
> 1. determine when a player has won
> 2. identify cells that are filled or empty
> 3. mark an empty cell
>
> /Roger
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



-- 
--
Regards,
KC



More information about the Beginners mailing list