data structure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ouzy27
    New Member
    • Apr 2008
    • 1

    #1

    data structure

    hey! i'm kind of new to java and i want to implement a Nine Men Morris game, but i'm still not sure about the data structure i should use. I'm thinking either 2 dimentional arrays or circular double linked lists. Please help me choose... what do you think is best. and if you choose link Lists please tell me how to connect the 3 lists together at specific links (U know to adjoin the squares together at the midpoint of each edge)
    thanxx
    cheers
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    I'd use several (simple) data structures that help in finding a move and an empty
    position as well as a three on a row situation. You can represent that board as
    49 bits; not every bit represents a valid board position. Those 49 bits can easily
    be stored in a single long int variable. Use a long for each player.

    A 1 (one) on a bit position means a piece is positioned at that particular location.
    Use a map Map<Long, List<Long>> that stores the potential legal moves given
    a certain board position. If the destination position is empty, you can move there.

    There are 16 possible 'three in a row' board positions so 16 longs will do here.
    If you bitwise and them successively with the board longs you can easily find
    out if such a three in a row position is present on the board.

    You figure out the rest.

    kind regards,

    Jos

    Comment

    Working...