def start_game(): board = [[EMPTY for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)] actor = X winner = None while has_zero(board) and not winner: (row, column) = make_turn(actor) if is_occupied(board, row, column): board[row - 1][column - 1] = actor actor = X if actor == O else O else: (row, column) = make_turn(actor) display_board(board) winner = get_winner(board) display_result(winner) if is_game_on(): start_game() else: print('Game over')
def show_next_hand(*args): """ Create the card list use Deck().deal and display_cardlist them""" global twentyfive_cards # disable show_next and enable show_best show_best25_hand_button["state"] = "normal" show_next_hand_button["state"] = "disabled" six_hands = Deck(6, 25, 3).deal() a = six_hands[0] twentyfive_cards = (sorted(a, key =rank_sort, reverse=True)) window.title("Play Pyramid Poker") w.delete("all") # clear out last hand display_board(w, X_GAP, Y_GAP, X_OFFSET, Y_OFFSET) show_twentyfive_cards() rank_button["state"] = "disabled" # clear out player, best and diff scores for previous hand x = 10 * X_GAP + 6 y = 3 * Y_GAP + 15 display_points_clear(x, y) # best hand points
def run_game(): # Player one is Xs # Player two is Os # initialize moves array moves = [] [moves.append('') for x in range(0,9)] count = 0 player_flip = True while count < 40: # eventually, run until a return condition is met if player_flip: index = int(input('Player 1, what is your move? ')) if index not in range(0,9): print('Input must be a digit between 0-8') continue if (moves[index] == ''): moves[index] = 'X' else: print('A move has already been played here.') continue else: index = random.randint(0,8) print("\n") if index not in range(0,9): continue if (moves[index] == ''): moves[index] = 'O' else: continue # check to see if game is over if winner(moves, 'X'): display_board.display_board(moves) print('Congrats Player 1! You win!') return True elif winner(moves, 'O'): display_board.display_board(moves) print('You lost: the bullies are going to take your lunch for the next year. Get better at Tic Tac Toe. Start over to cultivate another garden') return False if '' not in moves: display_board.display_board(moves) print('The game finished with no winner... Try harder next time.') return True player_flip = not player_flip count+=1 # to prevent infinite loop while testing display_board.display_board(moves) return # run_game()
@author: mahes """ from display_board import display_board, player_input, place_marker, win_check, choose_first, full_board_check, player_choice, replay print('Welcome to Tic Tac Toe Game') while True: theBoard = [' '] * 10 player1_marker, player2_marker = player_input() turn = choose_first() game_on = True print(turn + ' will play first') while game_on: if turn == 'Player 1': display_board(theBoard) print('Player 1 turn') position = player_choice(theBoard) place_marker(theBoard, player1_marker, position) if win_check(theBoard, player1_marker): display_board(theBoard) print('Congratulations! Player 1 is won') game_on = False else: if full_board_check(theBoard): display_board(theBoard) print('Oops! The Game is draw') break else: turn = 'Player 2'
def main(): # if __name__ == "__main__" positions_available = [' '] * 10 describe() sample() play_game = input('Are you ready to play? Enter Yes or No. : ') if play_game.lower().startswith('y'): game = True else: game = False print("See ya next time!") exit(0) # if not play_game.lower().startwith("y"): # exit(0) turn = player_turn() # rintu: invoke first_turn() print(turn +" has been selected by the system to go first.\n") player1_marker, player2_marker = marker() while game: if turn == 'Player 1': print("Player 1, Its your turn to input the index position.") player1_index = input_validification(positions_available) positions_available[player1_index]= player1_marker display_board(positions_available) if not spaces(positions_available): print("The match has been a draw match.\n") if replay(): positions_available = [' '] * 10 continue else: print("Thank you for playiing the game") break if check_for_win(positions_available,player1_marker): display_board(positions_available) print("Congratulations, Payer 1 you won the game!\nThank you for playing.") if replay(): positions_available = [' '] * 10 continue else: print("Thank you for playiing the game") game = False else: turn = 'Player 2' if turn == 'Player 2': print("Player 2, Its your turn to input the index position.") player2_index = input_validification(positions_available) positions_available[player2_index] = player2_marker display_board(positions_available) if not spaces(positions_available): print(spaces(positions_available)) print("The match has been a draw match.\n") if replay(): positions_available = [' '] * 10 continue else: print("Thank you for playiing the game") break if check_for_win(positions_available,player2_marker): display_board(positions_available) print("Congratulations, Player 2 you won the game!\nThank you for playing.") if replay(): positions_available = [' '] * 10 continue else: print("Thank you for playiing the game") game = False else: turn = 'Player 1'
player1_marker, player2_marker = player_input() turn = choose_first() print(turn + ' will go first. ') play_game = input('Ready to play? \'y\' or \'n\' ') if play_game == 'y': game_on = True else: game_on = False while game_on: if turn == "Player 1": # show the board display_board(the_board) # choose the position position = player_choice(the_board, turn) # place the marker on that postion and display the board place_marker(the_board, player1_marker, position) #check if they won if win_check(the_board, player1_marker): display_board(the_board) print('Player 1 HAS WON') game_on = False else: if full_board_check(the_board): display_board(the_board) print('GAME DRAW') game_on = False else:
def place_marker(board, marker, position): board[position] = marker display_board(board) print('hello')