Ejemplo n.º 1
0
def testFunction(function,
                 param_one,
                 param_two,
                 param_three,
                 param_four=False):
    result = function(param_one, param_two, param_three, param_four)
    formatted_start = converter.asBoardRepresentation(param_one)
    formatted_end = converter.asBoardRepresentation(result)
    print("At:", stringInterpret.pieceToString(param_two))
    print("Input".center(8))
    print(formatted_start)
    print("Output".center(8))
    print(formatted_end)
Ejemplo n.º 2
0
def CheckNorthWest(game_state, stringID, turn_colour, isTesting=False):
    NofChanges = 0  #Counts the number of pieces to change.
    PlaceHolder = ""  #This will be sections of string.
    slice_new_state = ""  #This will make a bigger section of the game state string from PlaceHolders.
    new_state = ""  #This is going to be the new string for the games state.
    MoveXID = 0  #This is going to be where the token across from
    other_colour = OtherColour(turn_colour)  #Determines the other colour.
    MoveID = stringID  #Makes a copy of the index of the current player's move.
    copy_state = game_state

    if stringID + constants.NORTHWEST > len(
            game_state) or stringID + constants.NORTHWEST < 0:
        return copy_state

    if game_state[stringID + constants.NORTHWEST] == "N":
        print("N detected")
        return copy_state

    #While the next token to check is the other colour.
    #NORTHWEST = -9
    while game_state[stringID + constants.NORTHWEST] == other_colour:

        #Catch invalid moves
        if NofChanges > (MoveID // 8) - 1:
            print("Out of bounds!")
            return copy_state

        if game_state[stringID + constants.NORTHWEST] == "N":
            print("N detected")
            return copy_state

    #		if game_state[stringID + constants.NORTHWEST] != other_colour and game_state[stringID + constants.NORTHWEST] != turn_colour:
    #			print("!= any colour")
    #			return game_state

    #Move to the next piece.
        stringID = stringID + constants.NORTHWEST

        #Counts one more for the number of pieces to change.
        NofChanges = NofChanges + 1

        #If the next piece is the turn player's colour....
        if game_state[stringID + constants.NORTHWEST] == turn_colour:

            #The token across is the ID of the last piece to change plus NORTHWEST
            MoveXID = stringID + constants.NORTHWEST

            #While there is still a number of pieces left to change.
            while NofChanges != 0:

                #Create a block of string with the character changed at the beginning
                PlaceHolder = turn_colour + game_state[stringID + 1:stringID -
                                                       constants.NORTHWEST]

                if turn_colour == "W":
                    colour = "White"
                else:
                    colour = "Black"

                ColumnRow = stringInterpret.pieceToString(stringID)
                column = ColumnRow[0]
                row = int(ColumnRow[1])
                #				turtleMove.placePiece(column, row, colour)

                #Create another block of string that was assembled from the blocks of Placeholder.
                slice_new_state = slice_new_state + PlaceHolder

                #Moveing backwards through the index of the pieces that need to be changed.
                stringID = stringID - constants.NORTHWEST

                #One less piece to change.
                NofChanges = NofChanges - 1

                #Testing
                if isTesting:
                    print(PlaceHolder, "PlaceHolder")
                    print(slice_new_state, "slice_new_state")
                    print(stringID, "Index of Change")
                    print(NofChanges, "Number of Changes left")

            #If there are no pieces left to change, assemble the new string.
            if NofChanges == 0:
                new_state = game_state[:MoveXID - constants.
                                       NORTHWEST] + slice_new_state + game_state[
                                           MoveID:]

                #Testing
                if isTesting:
                    print("01234567890123456789012345678901234567890")
                    print(game_state)
                    print(new_state)

        #Return the new string with all the pieces changed in the corresponding direction.
                return new_state
    return game_state
Ejemplo n.º 3
0
def CheckWest(game_state, stringID, turn_colour, isTesting=False):
    NofChanges = 0  #Counts the number of pieces to change.
    PlaceHolder = ""  #This will be a section of the new string.
    slice_new_state = ""  #This will be a bigger section of the new game state string.
    new_state = ""  #This going to be the new game stat.
    MoveID = 0  #This will make a copy of the index of the players move.
    MoveXID = 0  #This will be a marker for where the players piece is accross from their move.
    other_colour = OtherColour(
        turn_colour)  #This Determines the colour of the other player's piece.
    MoveID = stringID  #This will make a copy of the index of the players move.
    copy_state = game_state

    if stringID + constants.WEST > len(
            game_state) or stringID + constants.WEST < 0:
        return copy_state

    if game_state[stringID + constants.WEST] == "N":
        print("N detected")
        return copy_state

        #While the next token to check is the other colour.
        #WEST = -1
    while game_state[stringID + constants.WEST] == other_colour:
        #Possible statements for catching invalid moves.
        if NofChanges > (MoveID % 8) - 1:
            print("out of bounds")
            return copy_state

        if game_state[stringID + constants.WEST] == "N":
            print("N detected")
            return copy_state

        #Testing.
        if isTesting:
            print(NofChanges, "NofChanges Number of other colours")
            print(stringID + (constants.WEST), "index of other_colour")

        #Move on to the Next Token
        stringID = stringID + constants.WEST

        NofChanges = NofChanges + 1

        if game_state[stringID + constants.WEST] == turn_colour:

            NofPieces = NofChanges

            while NofChanges != 0:

                if turn_colour == "W":
                    colour = "White"
                else:
                    colour = "Black"

                ColumnRow = stringInterpret.pieceToString(stringID)
                column = ColumnRow[0]
                row = int(ColumnRow[1])
                #				turtleMove.placePiece(column, row, colour)

                stringID = stringID - constants.WEST

                NofChanges = NofChanges - 1

            if NofChanges == 0:
                new_state = game_state[:MoveID + 1] + (
                    turn_colour * NofPieces) + game_state[MoveID + NofPieces +
                                                          1:]
                return new_state
    return game_state
Ejemplo n.º 4
0
def CheckSouth(game_state, stringID, turn_colour, isTesting=False):
    NofChanges = 0  #Counts the number of pieces to change.
    PlaceHolder = ""  #This will be a section of the new string.
    slice_new_state = ""  #This will be a bigger section of the new game state string.
    new_state = ""  #This going to be the new game stat.
    MoveID = 0  #This will make a copy of the index of the players move.
    MoveXID = 0  #This will be a marker for where the players piece is accross from their move.
    other_colour = OtherColour(
        turn_colour)  #This Determines the colour of the other player's piece.
    MoveID = stringID  #This will make a copy of the index of the players move.
    copy_state = game_state

    if stringID + constants.SOUTH > len(
            game_state) or stringID + constants.SOUTH < 0:
        print("Out of range")
        return copy_state

    if game_state[stringID + constants.SOUTH] == "N":
        print("N detected")
        return copy_state

    #while game_state[stringID + constants.SOUTH] != "N":
    #While the next token to check is the other colour.
    #SOUTH = 8
    while game_state[stringID + constants.SOUTH] == other_colour:

        #Check if move is invalid
        if NofChanges > (8 - (MoveID // 8)) - 1:
            print("Out of bounds")
            return copy_state

        if game_state[stringID + constants.SOUTH] == "N":
            print("N detected")
            return copy_state

            #Move to the next piece.
        stringID = stringID + constants.SOUTH

        #Counts one more for the number of pieces to change.
        NofChanges = NofChanges + 1

        #If the next piece is the turn player's colour....
        if game_state[stringID + constants.SOUTH] == turn_colour:

            #The token across is the ID of the last piece to change plus SOUTH.
            MoveXID = stringID + constants.SOUTH

            #While there is still a number of pieces left to change.
            while NofChanges != 0:

                #Create a block of string with the character changed at the beginning.
                PlaceHolder = turn_colour + game_state[stringID + 1:stringID +
                                                       constants.SOUTH]

                if turn_colour == "W":
                    colour = "White"
                else:
                    colour = "Black"

                ColumnRow = stringInterpret.pieceToString(stringID)
                column = ColumnRow[0]
                row = int(ColumnRow[1])
                #		turtleMove.placePiece(column, row, colour)

                #Create another block of string that was assembled from the blocks of Placeholder.
                slice_new_state = PlaceHolder + slice_new_state

                #Moving backwards through the index of the pieces that need to be changed.
                stringID = stringID - constants.SOUTH

                #One less piece to change.
                NofChanges = NofChanges - 1

                #Testing
                if isTesting:
                    print(PlaceHolder, "PlaceHolder")
                    print(slice_new_state, "slice_new_state")
                    print(stringID, "Index of Change")
                    print(NofChanges, "Number of Changes left")

            #If there are no pieces left to change, assemble the new string.
            if NofChanges == 0:
                new_state = game_state[:MoveID + constants.
                                       SOUTH] + slice_new_state + game_state[
                                           MoveXID:]

                #Testing.
                if isTesting:
                    print(MoveID + constants.SOUTH, " MoveID")
                    print(MoveXID, " MoveXID")
                    print(
                        "012345678901234567890123456789012345678901234567890123"
                    )
                    print(game_state)
                    print(new_state)

        #Return the new string with all the pieces changed in the corresponding direction.
                return new_state
    return game_state
Ejemplo n.º 5
0
def CheckEast(game_state, stringID, turn_colour, isTesting=False):
    NofChanges = 0  #Counts the number of pieces to change.
    MoveID = 0  #This will make a copy of the index of the players move.
    NofPieces = 0
    other_colour = OtherColour(
        turn_colour)  #This Determines the colour of the other player's piece.
    MoveID = stringID  #This will make a copy of the index of the players move.
    new_state = ""
    copy_state = game_state

    if stringID + constants.EAST > len(
            game_state) - 1 or stringID + constants.EAST < 0:
        return copy_state
    #While the next token to check is the other colour.
    #EAST = 1
    #while game_state[stringID + constants.EAST] != "N":
    while game_state[stringID + constants.EAST] == other_colour:
        #Possible statements for catching invalid moves.
        if NofChanges > ((8 - (MoveID % 8)) - 1):
            print("Out of bounds.")
            return copy_state

        if game_state[stringID + constants.EAST] == "N":
            print("N detected")
            return copy_state

        #Testing.
        if isTesting:
            print(NofChanges, "NofChanges Number of other colours")
            print(stringID + (constants.EAST), "index of other_colour")

        #Move on to the Next Token
        stringID = stringID + constants.EAST

        NofChanges = NofChanges + 1

        if game_state[stringID + constants.EAST] == turn_colour:

            NofPieces = NofChanges

            while NofChanges != 0:

                if turn_colour == "W":
                    colour = "White"
                else:
                    colour = "Black"

                ColumnRow = stringInterpret.pieceToString(stringID)
                column = ColumnRow[0]
                row = int(ColumnRow[1])
                #					turtleMove.placePiece(column, row, colour)

                stringID = stringID - constants.EAST

                NofChanges = NofChanges - 1

            if NofChanges == 0:

                new_state = game_state[:MoveID + 1] + (
                    turn_colour * NofPieces) + game_state[MoveID + NofPieces +
                                                          1:]
                return new_state
    return game_state