From 4c665090b7ebffd44593f90cf0cb3061ae25e390 Mon Sep 17 00:00:00 2001 From: Harish-2003 <76206815+Harish-2003@users.noreply.github.com> Date: Thu, 16 May 2024 17:05:02 +0530 Subject: [PATCH 1/3] Create TIC_TAC_TOE_GAME.md --- contrib/mini-projects/TIC_TAC_TOE_GAME.md | 91 +++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 contrib/mini-projects/TIC_TAC_TOE_GAME.md diff --git a/contrib/mini-projects/TIC_TAC_TOE_GAME.md b/contrib/mini-projects/TIC_TAC_TOE_GAME.md new file mode 100644 index 0000000..8589e64 --- /dev/null +++ b/contrib/mini-projects/TIC_TAC_TOE_GAME.md @@ -0,0 +1,91 @@ +# Python Code For The Tic Tac Toe Game +# Tic Tac Toe Game + +## Overview + +### Objective +- Get three of your symbols (X or O) in a row (horizontally, vertically, or diagonally) on a 3x3 grid. + +### Gameplay +- Two players take turns. +- Player 1 uses X, Player 2 uses O. +- Players mark an empty square in each turn. + +### Winning +- The first player to align three of their symbols wins. +- If all squares are filled without any player aligning three symbols, the game is a draw. + +```python +print("this game should be played by two people player1 takes x player2 takes o") +board = [['1','2','3'],['4','5','6'],['7','8','9']] +x = 'X' +o = 'O' +def displayBoard(): + print(f" {board[0][0]} | {board[0][1]} | {board[0][2]}") + print("----------------------------------------") + print(f" {board[1][0]} | {board[1][1]} | {board[1][2]}") + print("----------------------------------------") + print(f" {board[2][0]} | {board[2][1]} | {board[2][2]}") + print("----------------------------------------") +def updateBoard(character,position): + row = (position-1)//3 + column = (position-1)%3 + board[row][column] = character +def check_win(): + for i in range(3): + if board[i][0] == board[i][1] == board[i][2]: + return 1 + elif board[0][i] == board[1][i] == board[2][i]: + return 1 + if board[0][2] == board[1][1] == board[2][0]: + return 1 + elif board[0][0] == board[1][1] == board[2][2]: + return 1 + return 0 +def check_position(position): + row = (position-1)//3 + column = (position-1)%3 + if board[row][column] == x or board[row][column] == o: + return 0 + return 1 +print("==============================welcome to tic tac toe game =====================") +counter = 0 +while 1: + if counter % 2 == 0: + displayBoard() + while 1: + choice = int(input(f"player{(counter%2)+1},enter your position('{x}');")) + if choice < 1 or choice > 9: + print("invalid input oplease try againn") + if check_position(choice): + updateBoard(x,choice) + if check_win(): + print(f"Congratulations !!!!!!!!!!!Player {(counter % 2)+1} won !!!!!!!!!!") + exit(0) + else : + counter += 1 + break + else: + print(f"position{choice} is already occupied.Choose another position") + if counter == 9: + print("the match ended with draw better luck next time") + exit(0) + else: + displayBoard() + while 1: + choice = int(input(f"player{(counter%2)+1},enter your position('{o}'):")) + if choice < 1 or choice > 9: + print("invalid input please try again") + if check_position(choice): + updateBoard(o,choice) + if check_win(): + print(f"congratulations !!!!!!!!!!!!!!! player{(counter%2)+1} won !!!!!!!!!!!!!1") + exit(0) + else: + counter += 1 + break + else: + print(f"position {choice} is already occupied.choose another position") + print() +``` + From 12878fd655130f6b643b07c8b516a1265f7ef768 Mon Sep 17 00:00:00 2001 From: Harish-2003 <76206815+Harish-2003@users.noreply.github.com> Date: Thu, 16 May 2024 17:13:10 +0530 Subject: [PATCH 2/3] Update index.md --- contrib/mini-projects/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mini-projects/index.md b/contrib/mini-projects/index.md index 82596a2..187d030 100644 --- a/contrib/mini-projects/index.md +++ b/contrib/mini-projects/index.md @@ -1,3 +1,3 @@ # List of sections -- [Section title](filename.md) +- [TIC_TAC_TOE_GAME](TIC_TAC_TOE_GAME.md) From 1ed2c2f5d8566616b54563c2130d37dbee05569d Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Thu, 23 May 2024 06:18:13 +0530 Subject: [PATCH 3/3] Rename TIC_TAC_TOE_GAME.md to tic-tac-toe.md --- contrib/mini-projects/{TIC_TAC_TOE_GAME.md => tic-tac-toe.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contrib/mini-projects/{TIC_TAC_TOE_GAME.md => tic-tac-toe.md} (100%) diff --git a/contrib/mini-projects/TIC_TAC_TOE_GAME.md b/contrib/mini-projects/tic-tac-toe.md similarity index 100% rename from contrib/mini-projects/TIC_TAC_TOE_GAME.md rename to contrib/mini-projects/tic-tac-toe.md