Skip to content

Gaymmasters/ML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ML

There are 2 files, that are used in our project. They are: main.py and hum_rob.py. The first file is designed to be played by two people, the second - by human and robot.

    Basic conditions:
  • The player_1 is indicated by the symbol "X"
  • The player_2 is indicated by the symbol "O"
  • Human is always the "X" and robot is the "O"
  • The current state of the playing field is saved in the array game_board
  • For convenience, abbreviations are used, where s is small, b is big. Thus, the code looks like this: b4s7 (move to the small cell 7 in the field with index 4)
  • main.py

    The file consists of 2 functions: game and victory.

      The game function accepts 4 parameters as input:
  • player
  • board
  • counter
  • last_move

  • This function is designed to handle player's actions. It returns new board, counter, last_move, previous_move.

      The victory function accepts 3 parameters as input:

  • player
  • board
  • previous_move

  • This function is used to check the move for a victory condition. It returns True, if the last move was victorious, and returns False, if it wasn't.
    Here is a table of variables with their descriptions
    paramdescrriptiontype
    playerwhich player's move are we consideringstr ('X', 'O')
    boardthe current state of the playing fieldarray
    countercounter for the number of movesint
    last_movethe ordinal number of the cell that the opponent was in during the last moveint
    previous_movethe ordinal number of the cell that the player made a move to during the last moveint

    To run the code, just enter the number of the cell to which you want to make a move.

    hum_rob.py

    The file consists of 4 functions: game, victory, minimax and optimal_move.

      The game function accepts 4 parameters as input:

  • player
  • board
  • counter
  • last_move

  • This function is designed to handle human actions. It returns board, counter, last_move and previous_move.

      The victory function accepts 3 parameters as input:

  • player
  • board
  • previous_move

  • This function is used to check the move for a victory condition. It returns True, if the last move was victorious, and returns False, if it wasn't.

      The minimax function accepts 4 parameters as input:

  • board
  • is_maximizing
  • depth
  • prev

  • This function is used to evaluate moves for a robot. It returns best_score.

      The optimal_move function accepts 3 parameters as input:

  • board
  • depth
  • prev

  • This function is used to select the best action for the robot. It returns best_move.

    To understand what each variable is responsible for, I made a table

    paramdescrriptiontype
    playerwhich player's move are we consideringstr ('X','O')
    boardthe current state of the playing fieldarray
    countercounter for the number of movesint
    last_movethe ordinal number of the cell that the opponent was in during the last moveint
    previous_movethe ordinal number of the cell that the player made a move to during the last moveint
    is_maximizingprovided that the move in question is made by a human, then among the following values it is necessary to look for the maximum and vice versabool
    depthyou can use this parameter to adjust the complexity of the model. The greater the depth, the more moves the robot calculates in advance, the more difficult it is to play against itint
    previs the same as previous_move, but it used in functions minimax and optimal_moveint

    To run the code, just enter the number of the cell to which you want to make a move.

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Contributors 2

    •  
    •  

    Languages