Exemplo n.º 1
0
    def display(self):
        """Use print board to display the contents of the board.

        Use the print board function to display a stringified version
        of the players board for reference during the game
        """
        return functions.print_board(self.board)
Exemplo n.º 2
0
def play():
    computer_symbol = 2
    human_symbol = 1
    computer_player = MinimaxPlayer(3, 3)

    board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

    print_board(board)

    player_starting = True

    while True:

        if game_finished(board, computer_symbol, human_symbol):
            break

        if player_starting:
            move = list(map(int, input('Enter your move [x,y]: ').split(',')))
            while not valid_move(move, board):
                print("Invalid move!")
                move = map(int, input('Enter your move [x,y]: '))

            board[move[1]][move[0]] = human_symbol
            computer_player.opponent_move(move[0], move[1])
            print_board(board)

            if game_finished(board, computer_symbol, human_symbol):
                break

        print('Computer is thinking...')
        time.sleep(1)

        move = computer_player.get_move()
        board[move[1]][move[0]] = computer_symbol

        print_board(board)

        if game_finished(board, computer_symbol, human_symbol):
            break

        player_starting = True
def game(size=8, bombs=8):
    """ Starts a game until all non-bomb positions are uncovered or until you find a bomb. """

    board = functions.assign_values(functions.make_board(size, bombs))
    moves = []
    print('Hi. Welcome to Minesweeper.:)')
    while True:
        functions.print_board(functions.visible_board(board, moves))
        position = input_position()
        if is_valid(position, size, moves):
            if board[position[0]][position[-1]] == '*':
                functions.print_board(board)
                print('Sorry. Game over:(')
                break
            functions.dig(board, moves, position)
            if len(moves) == (size**2 - bombs):
                functions.print_board(functions.visible_board(board, moves))
                print('Congratulations, you won!:)')
                break
        else:
            print('Invalid location. Try again.')
Exemplo n.º 4
0
# initialize the CSP
csp = CSP(variables, domains, constraints)

print('Set-up Time: {:0.5f} secs'.format(time.time() - start_time))

# print the inital board for smaller boards and if the user wants to see larger boards
if (n <= 15 or args.initial_board):
    print()
    print('Initial Board')
    b = create_board(n)
    for key, value in csp.domains.items():
        if constraints[key] > 0:
            b[value - 1][key - 1] = Colours.FAIL + 'Q' + Colours.ENDC
        else:
            b[value - 1][key - 1] = Colours.OKGREEN + 'Q' + Colours.ENDC
    print_board(b)
    print()

# to calculate the solve time
solve_time = time.time()

# max_steps defaults at 100
assignment = min_conflicts(csp, n, board)
# assignment = min_conflicts(csp, n, board, max_steps=500)

# if min-conflicts solved the problem
if assignment:
    # show times
    end_time = time.time()
    print('Solve Time: {:0.5f} secs'.format(end_time - solve_time))
    print('Total Time: {:0.5f} secs'.format(end_time - start_time))
Exemplo n.º 5
0
""" A program that implements the logic for a Tic-Tac-Toe game
    on an arbitrary size square board, e.g. 4x4, 5x5, etc.

    author: fizgi
    date: 23-Apr-2020
    python: v3.8.2
"""

from typing import List
from functions import initializer, print_board, row_checker, col_checker,\
    dgn_lr_checker, dgn_rl_checker, result

size, board = initializer()
winner_list: List[str] = []

print_board(board)

winner_list.extend(list(row_checker(board, size)))
winner_list.extend(list(col_checker(board, size)))
winner_list.extend(list(dgn_lr_checker(board, size)))
winner_list.extend(list(dgn_rl_checker(board, size)))

result(winner_list)