📘 Lesson · Lesson 95
Tic-Tac-Toe Game
इस Project के बारे में
💡 एक नज़र में
3x3 board पर simple दो-player Tic-Tac-Toe, board printing और win-checking logic दिखाता है।
Core Logic
Python
board = [" "] * 9
def show():
for i in range(0, 9, 3):
print(board[i], "|", board[i+1], "|", board[i+2])
def check_win(p):
wins = [(0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)]
return any(board[a]==board[b]==board[c]==p for a,b,c in wins)
board[0]=board[1]=board[2]="X"
show()
print("X wins:", check_win("X"))X | X | X
| |
| |
X wins: True
सारांश
- Board 9 cells की list है; show() इसे 3x3 grid के रूप में print करता है।
- check_win() player के लिए सभी 8 winning lines जाँचता है।
💻 लाइव कोड एडिटर
इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.