
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is a test file used as a Python interpreter.. Chunks of more or less useful pices of code! 3.3. The trash module, just a random test file.
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















ii
CHAPTER 1
Forewords
Dear reader, This is the cherish documentation of my TicTacToe program. I made this program with love and patience to learn how the use of a bunch of new technologies. For instance, the doc you are currently reading is compiled with sphinx, a very powerful and noob-unfriendly software.
CHAPTER 2
Let’s go to the point!
If you are in a hurry, please go the the main module page. Everything is explained there if you just want to run a quick simulation.
TicTacToe Documentation, Release 0.
4 Chapter 2. Let’s go to the point!
TicTacToe Documentation, Release 0.
3.2 List of all the packages
Submodules
core.BoardAndRules module
class BoardAndRules (game) Represents the rules of the game, saves the present state of the game and checks that the players follow the rules. Variables
6 Chapter 3. Contents:
TicTacToe Documentation, Release 0.
core.BoardState module
class BoardState (hash=None) Represents the physical board. Variables state (3-list (line) of 3-list (column)) – The state of the board: initialised with “0”: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] uses player.order to put “1” or “2” where the players play. Parameters hash (int, optional) – If hash is in **kwargs, it will be used to fill the board, default is None.
Examples
emptyB = BoardState() fullB = BoardState(hash=122121121) eq (other) Returns True if self.state and other.state are equal Return type bool hash () Returns An integer created by the concatenation of all the cases Return type int
Examples
[[0, 1, 2], [3, 4, 5], [6, 7, 8]] returns 12345678 Warning: First 0 is gone!
len () Returns the turn of the board: counts the 0 and deduces the turn T = 9 - nb(0) Return type int repr () Returns 3 lines representing the board (plus one line above and one under) with X and O instead of 1 and 2 Return type string copy () Returns A new identical copy of BoardState (useful for storage) Return type BoardState reset () Reset self.state for a new game: to [[0, 0, 0], [0, 0, 0], [0, 0, 0]] unhash (theHash)
3.2. List of all the packages 7
TicTacToe Documentation, Release 0.
core.Movement module
class Movement (player, place) Represents a movement played by a player. Variables
core.Player module
class Player (game, boardAR) ” Represents a random player, is subclassed to create human and intelligent players Variables
endOfGame () play () Calls randomPlay() randomPlay () Play a random movement (stupid: tries until a movement is not refused)
3.2. List of all the packages 9
TicTacToe Documentation, Release 0.
core.PlayerStatistic module
class PlayerStatistic (player)
newResult (game)
core.Simulation module
class Simulation (game)
start ()
Module contents
This is the Core package of the Game, it contains the primary classes of the game that are all needed to start a series of games between two random players.
Importation
The clean way to import the core package is: from core import (^) *
This may seem like a bad idea but the importation process in controlled in the core/init.py file. All the following classes will be imported:
Use
To use the imported classes, just write: game = Game() bAndR = BoardAndRules() # etc...
no need to use core.Game.Game(). This is made possible thanks to the use of from core.Game import Game in the core/init.py file.
10 Chapter 3. Contents:
TicTacToe Documentation, Release 0.
play () Plays a first random movement and then tries to complete lines
players.Memory module
class Memory
addGame (game) Add a game in the dictionary pastGames : •key = hash of the state before the wining movement •value = the Movement.place (couple [x,y]) that linked to the victory Parameters game (Game) – the ended Game instance to save
Warning: Does not check is the result is an even or a victory
Module contents
This is the Players package: it contains Player’s subclasses that try to develop some kind of intelligence...
Importation
Do as you want, there is nothing special in the players/init.py file.
Use
To use the imported classes, just write: Game()
no need to use core.Game.Game(). This is made possible thanks to the addition of the core/ folder path to the Python path and the use of from core.Game import Game in the init.py file.
Submodules
misc.Tools module
class Analyze
static createMovingRatios (resultsList, window) static createTotalRatios (resultsList) static extractMovingAverage (list, window)
12 Chapter 3. Contents:
TicTacToe Documentation, Release 0.
static replaceInList (l, sample, newSample) class Plot
static plotMovingRatio (player, window=20) static plotTotalRatio (player) static writeResultsInConsole (resultsList, precision=10)
Module contents
3.3 The trash module, just a random test file
This is a test file used as a Python interpreter.. Chunks of more or less useful pices of code!
3.3. The trash module, just a random test file 13
CHAPTER 4
Indices and tables
TicTacToe Documentation, Release 0.
16 Chapter 4. Indices and tables