Home python python cross-tick-tags with ii

python cross-tick-tags with ii

Author

Date

Category

How to make instead of 2 players playing computer simply chose random empty places (with an explanation of the solution if you can)

from random import randint
  While True:
    Board_size = 3.
    Board = [i for i in Range (9)]
    is_winner = false
    Current_Player = Randint (0, 1)
    markers = {0: 'o', 1: 'x'}
    Available_TurnS = (X for x in Range (9))
    DEF Draw_Board ():
      res = ""
      For i, V in Enumerate (Board):
        res + = STR (V) + ""
        IF (I + 1)% Board_size == 0:
           res + = "\ n"
      PRINT (RES)
    Def Validate (Value = ""):
      If not value.isdigit () and int (Value) Not in Available_Turns:
        Raise Valueerror ("ENTER VALID VALUE AND TRY AGAIN")
      If Board [INT (VALUE)] IN ('X', 'O'):
        Raise Valueerror ("This Value Has Already Played")
      IF '.' IN VALUE:
        Raise Valueerror ('Number Must BE INT')
    DEF Check_Winner ():
      CURRENT_MARKER = MARKERS [CURRENT_PLAYER]
      If Board [0] == CURRENT_MARKER AND BOARD [4] == CURRENT_MARKER AND BOARD [8] == CURRENT_MARKER OR \
          Board [2] == CURRENT_MARKER AND BOARD [4] == CURRENT_MARKER AND BOARD [6] == CURRENT_MARKER OR \
          Board [0] == CURRENT_MARKER AND BOARD [1] == CURRENT_MARKER AND BOARD [2] == CURRENT_MARKER OR \
          Board [3] == CURRENT_MARKER AND BOARD [4] == CURRENT_MARKER AND BOARD [5] == CURRENT_MARKER OR \
          Board [6] == CURRENT_MARKER AND BOARD [7] == CURRENT_MARKER AND BOARD [8] == CURRENT_MARKER OR \
          Board [0] == CURRENT_MARKER AND BOARD [3] == CURRENT_MARKER AND BOARD [6] == CURRENT_MARKER OR \
          Board [1] == CURRENT_MARKER AND BOARD [4] == CURRENT_MARKER AND BOARD [7] == CURRENT_MARKER OR \
          Board [2] == CURRENT_MARKER AND BOARD [5] == CURRENT_MARKER AND BOARD [8] == CURRENT_MARKER:
        Return True.
      ELSE:
        Return False
    For i in Range (9):
      Try:
        INPUT_ERROR = TRUE.
        Draw_Board ()
        While Input_error:
          Choice = Input (F "Player {MARKERS [CURRENT_PLAYER]} ENTER Your Number: \ n")
          Validate (Choice)
          INPUT_ERROR = FALSE.
        Board [INT (Choice)] = markers [Current_Player]
        If Current_Player == 1:
         # Check winner
        is_winner = check_winner ()
        If is_winner == True:
          Print (F'Player {MARKERS [CURRENT_PLAYER]} WON THE GAME !! ')
          Break
        Current_Player = 0 if Current_Player == 1 ELSE 1
        # If_winner == True:
      Except Valueerror AS EX:
        Print (EX)
    If is_winner == False:
      Print ('Draw')
    REPLAY = INPUT ("Would you like to replay? (Y or N)")
    If Replay == "Y":
      Continue.
    ELSE:
      Break

Answer 1, Authority 100%

did such a bot. Let crosses – a player, and Noliki – AI. As follows: (the player goes first) you must check 3 cells horizontally, vertical and diagonal. If there are two cross and there are no zolikov, then the bot must put a talker in the line where two crosses to not lose. If there is no such line (with two cross), then the bot should build its zolikov line for victory. He must find such a line where there is no crosses and must with the maximum number of zolikov. After he found this line, he should put a nolik there. All this for the 3×3 field

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions