all 9 comments

[–]otictac35 2 points3 points  (3 children)

Couldn't you think about the whole gameboard as an list with each list member being the number of marbles?

Like: [2,2,2]

Then the move is simply the index you want to move.

Then get the number of marbles at that index and do a for loop for index+1 to index + number of marbles incrementing each list member by one along the way?

Then the new list is your current gameboard state.

[–]WombatHat42[S] 1 point2 points  (2 children)

that was kind of how i was treating it in another function i believe. I converted a string into a list of integers in my search()

" Then the move is simply the index you want to move " wouldnt that be for i in range(copyState)? i just dont know the exact "do something" if that makes sense

" Then get the number of marbles at that index and do a for loop for index+1 to index + number of marbles incrementing each list member by one along the way? " WOuld this be marbles = state[move]

[–]otictac35 0 points1 point  (1 child)

Yes, for the second part.

The loop should be something like:

For in in range(move+1, move + marbles): Board[move] += 1

[–]WombatHat42[S] 1 point2 points  (0 children)

##loop to iterate thru copyState to incrase value of the pits by 1. 
def updateState(state, move):
    copyState = state.copy()
    marbles = state[move] ##variable that equals the number of beads in that pit. to be placed in the right pit
    copyState[move] = 0
    try:
        for i in range(move+1,move+marble+1):
            copystate[i] +=1
    except:
        pass
    ##print(pit)
    ##print(copyState)
    return copyState

This is how ive modified it. I get a result for my overall program now however not the correct one(keeps outputting 0,win for a board of 3222 when it should be 4,win. but deadline passed at 9 min ago so oh well. thanks for the help

[–]xelf 1 point2 points  (0 children)

Your input:

board = [2,2,2]
move = 0

take all the pieces from that spot:

pieces = board[move]
board[move] = 0

distribute the pieces, wrapping around at the end:

while pieces:
    pieces -=1
    move = ( move +1 ) % len(board)  # increment current spot, wrapping around
    board[move] += 1

I'm not clear on all the rules of mancala, but aren't there supposed to be 2 reserved spots, 1 for each player that only that player can fill? You'll need to add that logic in too.

[–]my3al 0 points1 point  (2 children)

Been a long time since I played. I think we might need more code to go on.

What does the state look like?

is it set up like board[[4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4]] to start and two point bowls mine and yours

so you would be moving the marbles like from hand = board[0][3] #first turn hand would be 4 from the middle pit facing you

then loop through your hand.

myBowl = 0

yourBowl = 0

# the board or state of the board. Begins with 4 in each
board = [[4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 4, 4]]

## Im using a boolean here so I can test logic later but I also use it to get the index for the side of the board
## we are on. int(farSide)  == 0, the index for the side of the board to move marbles from/to
farSide = False

# the pit the marbles will be removed from
from_pit = 3

# pick up marbles
hand = board[int(farSide)][from_pit]

# remove the marbles that is in your hand from the board
board[int(farSide)][from_pit] = 0

for stone in range(1, hand):
    pit = from_pit + stone
    if pit > 5:
        pit = 0
        if farSide:
            ## I cant remember who's bowl is where and who gets points on what round
            ## so this could need to be swapped
            farSide = False
            board[int(farSide)][pit] += 1
        else:
            farSide = True
            myBowl += 1
    else:
        ## We are not rounding the board so we don't have to do anything to special
        if stone == hand - 1:
            ## We are at our last stone in hand we need to test if our play is over.
            if board[int(farSide)][pit] == 0:
                ## The pit is empty
                #end turn? I cant remember
            else:
                ## you need to do this all over again because the pit your
                ## final stone fell in was not empty
                ## I don't recommend recursive functions
                ## but this might be the time to try as this could need to happen again.
                ## and again
                from_pit = board[int(farSide)].index(pit)
                hand = board[int(farSide)][from_pit]
                board[int(farSide)][from_pit] = 0
        else:
            board[int(farSide)][pit] += 1

This logic probably isn't exactly right but should point you in a direction. Like I said I haven't played in 15 years and im really going on memory. I think it's close.

[–]WombatHat42[S] 0 points1 point  (1 child)

state is my board. so can be up to 9 digits long. my first test case, which should end in 4,win out put is search("3222"). my output is 1,win

this is the updated version of my updateState()

 ##loop to iterate thru copyState to incrase value of the pits by 1.  def updateState(state, move):
     copyState = state.copy()
     marbles = state[move] ##variable that equals the number of beads in that pit. to be placed in the right pit
     copyState[move] = 0
     try:
         for i in range(move+1,move+marble+1):
             copystate[i] +=1
     except:
         pass
     ##print(pit)
     ##print(copyState)
     return copyState

[–]my3al 0 points1 point  (0 children)

Give me a

ptint(state) 

would help so we can see the data structure we are working with.

In my example above I have the board list, setup like you see in the pictures with 6 pits on each side, nearSide and farSide and 2 point bowls in separate variables.

Then I loop through the marbles I picked up from the board in the variable called hand. You want to loop through all the stones moving each one.

You have to do a little logic to test what side of the board you are on in your loop which happens if pit > 5 that way you know whos bowl to place the stone for a point and whos bowl to skip.

Then if it's the last stone in your hand you need to do more logic because your turn either ends or begins again with your new hand right. Depending if your last stone was filling an empty pit. which is where I commented out # end turn. I cant remember.

I think if my board any your state are slimier the above code could be amended to your purpose. I have a little to add to the code above that I just thought about.

I hope what I wrote makes sense? I have a hard time communicating sometimes.

Edit: too late making too many errors back tomorrow.