this is the implemntaion of the game TicTakToe using Raw Sockets in python I divided my python program in to 9 modules or functions
What happens is it firstly calls the form_submit function to check if a submission has been made
once it has been made the player_move function is invoked for the human’s movement on the board
then after that inside a while loop the function computer_turn is made so that if the computer chooses a spot which has already been used
it won’t select that space again after all that is done then the final function who_wins to decide who wins is called.
like this diagonal and the reverse diagonal and the first row and so on Then I checked them with the check_Xcheck_O
check_X = when a player makes a move
check_O = when a computer makes a move
I made a random number generator between 1 to 9. So what I did was ever time a move is made it is inserted in to a variable called history so every move gets recorded in the history array and If a move is present in the history array the computer will choose another move.
*I also made a supplementary 2D array for calculating where in the board a player has made a move and so this gave me a way to calculate who would win
How to run 1) open up rawsockets.py and run it it will sayServing HTTP on port 8888
2) Open up Browser and type localhost:8888
3) you will see a display like so: