Ejemplo n.º 1
0
def game_start(game_board, playerTile, computerTile, turn):
    while True:
        if turn == 'player':
            print(turn+"s turn")
            # gia ton paixth pairnoyme tis egkyres kinhseis
            # kai ektypwnoyme to voithitiko tamblo
            validMoves = board.getBoardWithValidMoves(game_board, playerTile)
            print(board.getScoreOfBoard(game_board))
            game_board = board.getPlayerMove(game_board, playerTile, validMoves)
            # an o antipalos den exei kinhseis stamatame kai ektypwnoyme skor
            if board.getValidMoves(game_board, computerTile) == []:
                break
            else:
                turn = 'computer'

        else:
            # typwnoyme enhmeromeno board
            board.printBoard(game_board)
            print(board.getScoreOfBoard(game_board))
            input("press Enter for AI turn")
            # ekteloyme kinhsh gia ton AI
            game_board = board.getComputerMove(game_board, playerTile, computerTile)
            board.printBoard(game_board)
            print(board.getScoreOfBoard(game_board))
            input("Press Enter to continue")
            # an o antipalos den exei kinhsh telos
            if board.getValidMoves(game_board, playerTile) == []:
                break
            else:
                turn = 'player'
    # sto telos typwnoyme skor
    return end_game(game_board, playerTile, computerTile)
Ejemplo n.º 2
0
def run():
	board = boardSetup()
	players = playerSetup(board)
	while True:
		board.printBoard()
		currPlayer = players[0]
		currPlayer.makeMove(board)
		if currPlayer.laps == 0:
			win(currPlayer)
			break
		players = players[1:] + [currPlayer]
Ejemplo n.º 3
0
def main():
    spaces = board.getStartBoard()
    turn = getWhoMovesFirst()
    depthLim = getDepthLim()
    gameEnd = False

    while not gameEnd:
        print("-------------------------------------")
        board.printBoard(spaces)

        if turn == board.SOUTH:
            print("South's turn")
            print("-------------------------------------")
            playerMove(spaces, turn)
            turn = board.NORTH
        elif turn == board.NORTH:
            print("North's turn")
            print("-------------------------------------")
            tempNode = Node.Node(spaces[:], 0, depthLim)
            value, state = Node.ABPruning(tempNode, -1000000, 1000000)
            success, errorMessage = board.move(spaces, board.NORTH,
                                               str(state.cupMove))
            print("\tMoving Cup:", state.cupMove, "\n\tTranslated to Cup:",
                  state.cupMove - 7)
            turn = board.SOUTH
        else:
            print("Error: Turn set to invalid player.")
            break
        gameEnd = board.checkEndState(spaces)
        if gameEnd:
            board.printBoard(spaces)
            print("-------------------------------------")
            input("Game has ended. Hit enter to see results")
            print("\n----- RESULTS -----")
            print("South Points:", board.getScore(spaces, board.SOUTH))
            print("North Points:", board.getScore(spaces, board.NORTH))

            if board.getScore(spaces, board.SOUTH) > board.getScore(
                    spaces, board.NORTH):
                print("South wins!")
            elif board.getScore(spaces, board.SOUTH) < board.getScore(
                    spaces, board.NORTH):
                print("North wins!")
            else:
                print("It's a tie.")
Ejemplo n.º 4
0
def printTree(root):
    global nodeCounter
    depthCounter = 0

    if root:
        #then print the data of node
        print("Layer: " + str(depthCounter))
        print("Node: " + str(nodeCounter))
        print("Heuristic: " + str(root.heuristic))
        board.printBoard(root.state)
        nodeCounter += 1
        depthCounter += 1

        for i in range(len(root.nextTurns)):
            print("Layer: " + str(depthCounter))
            print("Node: " + str(nodeCounter))
            print("Heuristic: " + str(root.nextTurns[i].heuristic))
            board.printBoard(root.nextTurns[i].state)
            nodeCounter += 1

        depthCounter += 1

        for j in range(len(root.nextTurns)):
            for k in range(len(root.nextTurns[j].nextTurns)):
                print("Layer: " + str(depthCounter))
                print("Node: " + str(nodeCounter))
                print("Heuristic: " +
                      str(root.nextTurns[j].nextTurns[k].heuristic))
                board.printBoard(root.nextTurns[j].nextTurns[k].state)
                nodeCounter += 1

        depthCounter += 1

        for l in range(len(root.nextTurns)):
            for m in range(len(root.nextTurns[l].nextTurns)):
                for n in range(len(root.nextTurns[l].nextTurns[m].nextTurns)):
                    print("Layer: " + str(depthCounter))
                    print("Node: " + str(nodeCounter))
                    print("Heuristic: " + str(
                        root.nextTurns[l].nextTurns[m].nextTurns[n].heuristic))
                    board.printBoard(
                        root.nextTurns[l].nextTurns[m].nextTurns[n].state)
                    nodeCounter += 1
    nodeCounter = 0
Ejemplo n.º 5
0
import board
import os
from random import randint
i = 0
error = ""
turns = 8
offset = 0
unused_variable = os.system("cls")
board.printBoard()
ship = board.genShip(randint(0,4), randint(0,4))

while i < turns:
    print(error)
    print("Turn " + str(i + 1))
    print()
    while True:
        try:
            guessY = int(input("guess X: "))
            guessX = int(input("guess Y: "))
        except ValueError:
            unused_variable = os.system("cls")
            board.printBoard()
            print("Thats not even a number")
            print("Turn " + str(i+1))
            print()
        else:
            break
        
    
    if guessY > 5 or guessX > 5 or guessY <= 0 or guessX <= 0:
        error = "You must guess within the ocean"
Ejemplo n.º 6
0
#   with the white player going first, using a defensive strategy,
#   and the black player going second, using an offensive strategy.

import board
import tree
import brain
import copy

print("\n################### Start alice.py ###################\n")

turnCounter = 0
mainBoard = board.createBoard()
board.setStartingPieces(mainBoard)

print("Turn: " + str(turnCounter))
board.printBoard(mainBoard)

while (not (board.endGame(mainBoard))):

    #debugging
    #print("##########from turn " + str(turnCounter) + " ##########\n")

    #pick a move, get possible moves
    currentState = tree.Node(0, copy.deepcopy(mainBoard))

    #debugging
    #print("currentState tree:")
    #tree.printTree(currentState)

    currentState.nextTurns = brain.getPossibleStates(currentState, turnCounter,
                                                     0)
Ejemplo n.º 7
0
#Main file
#created by Noah and Pia
import cars
import board

youWin = False

#START OF GAME

#Display of gameboard 
gameBoard = board.decideDiff() 

board.printBoard(gameBoard) 


while youWin == False:
    piece = input("Please enter the car you would like to move (ex: 11): ")
    endpos = input("Please enter the end position (of the top most piece or left most piece) piece of the car (ex: Aa): ")

    #Placing appropriate variables into pre-defined functions
    endpos = cars.readUser(endpos)
    direction = cars.carDirection(piece, gameBoard)

    gameBoard = cars.correctMove(endpos, piece, gameBoard)
    board.printBoard(gameBoard)

#win condition
    if gameBoard[17] == '00':
        youWin = True
#Jackie Chan display when win
if youWin ==  True:
Ejemplo n.º 8
0
def game():
    moves = defaultdict(dict)
    status=False
    turn = 'X'
    count = 0
    g = b.gameBoard.copy()
    vals = b.value.copy()
    for i in range(9999):
        b.printBoard(g)
        if status==True:
            #restart(g)
            break
        if turn == 'X':
            print("It's your turn," + turn + ".Move to which place?")
            val = 3
            move = get_input()
            moves[count]['Test']=move
        else:
            val = 5
            move = playai(vals,g)
            print("Ai played to place " + move)
            moves[count]['AI']=move


        if g[move] == ' ':
            g[move] = turn
            vals[str(move)] = val
            count += 1
        else:
            print("That place is already filled.\nMove to which place?")
            continue


        if count >= 5:
            if g['7'] == g['8'] == g['9'] != ' ':  # across the top
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['4'] == g['5'] == g['6'] != ' ':  # across the middle
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['1'] == g['2'] == g['3'] != ' ':  # across the bottom
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['1'] == g['4'] == g['7'] != ' ':  # down the left side
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['2'] == g['5'] == g['8'] != ' ':  # down the middle
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['3'] == g['6'] == g['9'] != ' ':  # down the right side
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['7'] == g['5'] == g['3'] != ' ':  # diagonal
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break
            elif g['1'] == g['5'] == g['9'] != ' ':  # diagonal
                b.printBoard(g)
                print("\nGame Over.\n")
                print(" **** " + turn + " won. ****")
                status = True
                break

            moves[count]['winner']=turn

                #Tie.
        if count == 9:
            status=True
            print("\nGame Over.\n")
            print("It's a Tie!!")
            moves[count]['winner']="TIE"

        # Change
        if turn == 'X':
            turn = 'O'
        else:
            turn = 'X'

    print(moves)
            #Restart.
   # if (status==True):
    #    restart(g)

    return moves
Ejemplo n.º 9
0
#Main file
#created by Noah and Pia
import cars
import board

youWin = False

#START OF GAME

#Display of gameboard
gameBoard = board.decideDiff()

board.printBoard(gameBoard)

while youWin == False:
    piece = input("Please enter the car you would like to move (ex: 11): ")
    endpos = input(
        "Please enter the end position (of the top most piece or left most piece) piece of the car (ex: Aa): "
    )

    #Placing appropriate variables into pre-defined functions
    endpos = cars.readUser(endpos)
    direction = cars.carDirection(piece, gameBoard)

    gameBoard = cars.correctMove(endpos, piece, gameBoard)
    board.printBoard(gameBoard)

    #win condition
    if gameBoard[17] == '00':
        youWin = True
#Jackie Chan display when win
Ejemplo n.º 10
0
    def game_mechanism(self):
        theBoard = {'7': ' ', '8': ' ', '9': ' ',
                    '4': ' ', '5': ' ', '6': ' ',
                    '1': ' ', '2': ' ', '3': ' '}

        board_keys = []

        for key in theBoard:
            board_keys.append(key)

        turn = 'X'
        count = 0

        for i in range(10):
            printBoard(theBoard)
            print("It's your turn," + turn + ".Move to which place?")

            move = input()

            if theBoard[move] == ' ':
                theBoard[move] = turn
                count += 1
            else:
                print("That place is already filled.\nMove to which place?")
                continue

            if count >= 5:
                if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break
                elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ':
                    printBoard(theBoard)
                    print("\nGame Over.\n")
                    print(" **** " + turn + " won. ****")
                    break

        restart = input("Do want to play Again?(y/n)")
        if restart == "y" or restart == "Y":
            for key in board_keys:
                theBoard[key] = " "
Ejemplo n.º 11
0
printTurns = True
numGames = 1
setMinimax = False

for i in range(numGames):

    print("\n##### Start glados GAME #####\n")
    
    mainBoard = board.board(8, 8, '[]', ['L', 'F', 'R'])

    player01 = player.player('White', 'WW', 0, 1, [player.moveWall], True, mainBoard)
    player02 = player.player('Black', 'BB', 1, 1, [player.moveWall], True, mainBoard)
    player.setOpponents(player01, player02)
    board.setStartingPieces(player01)
    board.setStartingPieces(player02)
    board.printBoard(mainBoard.field)
    #display.draw_board(mainBoard)
    currentPlayer = player01
    turnCounter = 0

    while(not(brainV2.endGame(mainBoard.field, currentPlayer.opponent))):

        #print("Current Player:" + str(currentPlayer))
        #print(".", end="")


        currentState = tree.Node(0, copy.deepcopy(mainBoard.field))
        currentState.nextTurns = brainV2.getPossibleStates(currentPlayer, currentState, turnCounter, 0)

        if setMinimax:
            start = 0
Ejemplo n.º 12
0
def printMap(map, numberOfOpenNodes, numberOfClosedNodes):
	print('Number of closed nodes: ' + str(numberOfClosedNodes))
	print('Number of opened nodes: ' + str(numberOfOpenNodes))
	board.printBoard(map)	
	print('__________________________________________')
	print('')