Exemplo n.º 1
0
def repl():
    board = make_board()
    player = "X"
    opp = "O"

    from minmax_ai import AI
    ai = AI(ai_piece=opp,
            opp=player,
            depth=5,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)

    print "You are X"
    print "Enter your moves as a zero-indexed col number"

    while(True):
        print
        print "Your Turn: "
        print_board(board)
        input = raw_input()
        col = int(input)
        if board[col][0] != blank:
            print "Invalid move!"
            continue        
    
        board = next_state(board, player, col)
        print_board(board)
        winner = get_winner(board, player, opp)
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print 
        print "Their turn..."
    
        score, ai_move = ai.get_move(board)
        print ai_move
        board = next_state(board, opp, ai_move)
        print_board(board)
        winner = get_winner(board, player, opp)
    
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break
Exemplo n.º 2
0
def repl():
    board = make_board(3)
    player = "X"
    opp = "O"

    from minmax_ai import AI
    ai = AI(ai_piece=opp,
            opp=player,
            depth=9,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)
    
    print "You are X"
    print "Enter your moves as: col row"

    while(True):
        print
        print "Your Turn: "
        print_board(board)
        input = raw_input()
        y, x = map(int, input.split())
        if board[y][x] != blank:
            print "Invalid move!"
            continue        
    
        board = next_state(board, player, (y,x))
        print_board(board)
        winner = get_winner(board)
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print 
        print "Their turn..."
    
        score, ai_move = ai.get_move(board)
        print ai_move
        board = next_state(board, opp, ai_move)
        print_board(board)
        winner = get_winner(board)    
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break
Exemplo n.º 3
0
def repl():
    board = make_board()
    player = "X"
    opp = "O"

    ai = AI(ai_piece=opp,
            opp=player,
            depth=5,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)

    print "You are X"
    print "Enter your moves as a zero-indexed col number"

    while (True):
        print
        print "Your Turn: "
        print_board(board)
        input = raw_input()
        col = int(input)
        if board[col][0] != blank:
            print "Invalid move!"
            continue

        board = next_state(board, player, col)
        print_board(board)
        winner = get_winner(board, player, opp)
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print
        print "Their turn..."

        score, ai_move = ai.get_move(board)
        print ai_move
        board = next_state(board, opp, ai_move)
        print_board(board)
        winner = get_winner(board, player, opp)

        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break
Exemplo n.º 4
0
def repl():
    board = make_board(3)
    player = "X"
    opp = "O"

    ai = AI(ai_piece=opp,
            opp=player,
            depth=9,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)

    print "You are X"
    print "Enter your moves as: col row"

    while (True):
        print
        print "Your Turn: "
        print_board(board)
        input = raw_input()
        y, x = map(int, input.split())
        if board[y][x] != blank:
            print "Invalid move!"
            continue

        board = next_state(board, player, (y, x))
        print_board(board)
        winner = get_winner(board)
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print
        print "Their turn..."

        score, ai_move = ai.get_move(board)
        print ai_move
        board = next_state(board, opp, ai_move)
        print_board(board)
        winner = get_winner(board)
        if game_over(board, player, opp):
            if winner != None:
                if winner == player:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break
Exemplo n.º 5
0
def repl():
    board = make_board(5)
    player = PAWN_PLAYER
    opp = PAWN_IA

    ai = AI(ai_piece=opp,
            opp=player,
            depth=9,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)

    turn = 0
    
    board = next_state(board, player, (0,0))
    print_board(board)
    
    print "You are X"
    
    while(True):
        print
        print "Your Turn: "
        #input = raw_input()
        try:
            y = 0
            x = int(raw_input())
            playerLastMove = x
            if x > 4 or x < 0:
                print "Invalid move! Must be a number between 0-4." 
                continue
        except IndexError:
            print "Invalid move! Out of board cordinates."
            continue
        except ValueError:
            print "Invalid move!"
            continue
    
        board = next_state(board, player, (x,y))
        print_board(board)
        vW,hW,draw = get_winner(board)    
        if game_over(board, player, opp):
            if vW :
                print "The real player win!"
            elif hW:
                print "The IA win!"
            else:
                print "Draw!"
            break
        print 
        
        #IA controls
        sys.stdout.write('The IA is thinking and the move is ')
        sys.stdout.flush()
        if turn == 0 :
            print "(0, "+str(4)+")"
            board = next_state(board, opp , (0,4))
        else:
            score, ai_move = ai.get_move(board)
            print ai_move
            board = next_state(board, opp, ai_move)
        #End IA controls

        #Player2 controls
        '''
        while True:
            try:
                y = int(raw_input())
                x = 0 
                if y > 4 or y < 0:
                    print "Invalid move! Must be a number between 0-4." 
                    continue
                break
            except IndexError:
                print "Invalid move! Out of board cordinates."
                continue
            except ValueError:
                print "Invalid move!"
                continue
        board = next_state(board, opp, (x,y))
        #'''
        #End player2 controls

        print_board(board)
        vW,hW,draw = get_winner(board)    
        if game_over(board, player, opp):
            if hW :
                print "The IA win!"
            elif vW:
                print "The real player win!"
            else:
                print "Draw!"
            break

        turn = turn + 1
Exemplo n.º 6
0
def repl():
    global GHOST_C, GHOST_R
    board = make_board()

    from minmax_ai import AI
    ai = AI(ai_piece=OPP,
            opp=PLAYER,
            depth=5,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)
    
    print "You are X"
    print "The numbers at the bottom-right corner of cells is the col-row number. Seperate the digits when entering you move"
    print "Enter your moves as: from_col from_row to_col to_row"
    print "NOTE: When jumping a piece, enter the from col-row and the col-row of the FIRST PIECE to jump, NOT the space after it. Chain jumps will automaticlaly be performed for you"
    print "Your pieces are in GREEN, your opponenets are RED, and the ghost of where you opponent was is in WHITE"

    while(True):
        print
        print "Your Turn: "
        print_board(board)
        print possible_moves(board, PLAYER)
        input = raw_input()
        f_c, f_r, t_c, t_r = map(int, input.split())
      
        if not is_valid_move(board, PLAYER, f_c, f_r, t_c, t_r):
            print "Invalid move!"
            continue        
        
        board = next_state(board, PLAYER, (f_c, f_r, t_c- f_c, t_r - f_r))

        winner = get_winner(board)
        if game_over(board, PLAYER, OPP):
            if winner != None:
                if winner == PLAYER:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print 
        print "Their turn..."
    
        score, ai_move = ai.get_move(board)
        board = next_state(board, OPP, ai_move)
        ai_fc, ai_fr, ai_dc, ai_dr = ai_move
        GHOST_C, GHOST_R = ai_fc, ai_fr
        board[GHOST_C][GHOST_R] = GHOST_OPP
        print str((ai_fc, ai_fr)) + " -> " + str((ai_fc + ai_dc, ai_fr + ai_dr))

        winner = get_winner(board)    
        if game_over(board, PLAYER, OPP):
            if winner != None:
                if winner == PLAYER:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break
Exemplo n.º 7
0
def repl():
    global GHOST_C, GHOST_R
    board = make_board()

    from minmax_ai import AI
    ai = AI(ai_piece=OPP,
            opp=PLAYER,
            depth=5,
            game_over_fun=game_over,
            eval_fun=evaluate,
            moves_fun=possible_moves,
            next_state_fun=next_state)

    print "You are X"
    print "The numbers at the bottom-right corner of cells is the col-row number. Seperate the digits when entering you move"
    print "Enter your moves as: from_col from_row to_col to_row"
    print "NOTE: When jumping a piece, enter the from col-row and the col-row of the FIRST PIECE to jump, NOT the space after it. Chain jumps will automaticlaly be performed for you"
    print "Your pieces are in GREEN, your opponenets are RED, and the ghost of where you opponent was is in WHITE"

    while (True):
        print
        print "Your Turn: "
        print_board(board)
        print possible_moves(board, PLAYER)
        input = raw_input()
        f_c, f_r, t_c, t_r = map(int, input.split())

        if not is_valid_move(board, PLAYER, f_c, f_r, t_c, t_r):
            print "Invalid move!"
            continue

        board = next_state(board, PLAYER, (f_c, f_r, t_c - f_c, t_r - f_r))

        winner = get_winner(board)
        if game_over(board, PLAYER, OPP):
            if winner != None:
                if winner == PLAYER:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break

        print
        print "Their turn..."

        score, ai_move = ai.get_move(board)
        board = next_state(board, OPP, ai_move)
        ai_fc, ai_fr, ai_dc, ai_dr = ai_move
        GHOST_C, GHOST_R = ai_fc, ai_fr
        board[GHOST_C][GHOST_R] = GHOST_OPP
        print str((ai_fc, ai_fr)) + " -> " + str(
            (ai_fc + ai_dc, ai_fr + ai_dr))

        winner = get_winner(board)
        if game_over(board, PLAYER, OPP):
            if winner != None:
                if winner == PLAYER:
                    print "You win!"
                else:
                    print "You lose!"
            else:
                print "Draw!"
            break