Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Python gui tic tac toe

25/10/2021 Client: muhammad11 Deadline: 2 Day

Python Assignment - Tic Tac Toe Game Using GUI

CSCI 503-1 Computer Assignment 4 Spring 2020 (20 points)

Tic-tac-toe is a game for two players, X and O, who take turns marking the spaces in a 3 x 3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is a winner. Write a python program to simulate playing this game. Draw the grid on your terminal screen and display your marks on the grid. You need to import the graphics package into your program, download and install the Xming program (from the Internet) to your computer to activate the graphics package. If you’re using PuTTY to access the tiger machine, you need to enable X11 forwarding, but if you’re directly using the ssh to access the tiger, you need to use the ssh with –X option. One of the players starts playing the game who is randomly chosen between the two players. You can play the game for as many times as you wish, but for a final test, do it for 12 consecutive games. To start your program, follow the example on page 100 of the textbook. To simulate a game, you can use a random number generator (RNG), randrange ( ), importing from the random package, and to get the same sequence of random numbers for each time to execute the program, set the seed value to 1 in your main ( ) routine. The functions described below are just suggestions. You can design your program anyway you like but make it sure that it generates the correct results.

• def main ( ): For each new play, to create a window on the terminal screen for a given size, say 400 x 400 pixels, it calls the function draw_board ( ) that draws a 3 x 3 grid on the screen. It prints the game number and calls the function init_play ( ) to choose the player who makes the first move. To simulate of playing a game, it calls the function play ( ), which returns the identity of the winner or returns None if the game is a draw and updates the number of wins for the winner. After each game, it pauses for the user input to continue to the next game, waiting for the user to enter a “yes” and closes the window for a fresh start. If the user prompt is a “no”, it quits playing the games and calls the function print_stat ( ) to print out the final winning scores.

• def draw_board ( win ): In addition to drawing horizonal and vertical lines on the grid, this function also prints the corresponding index values from 0 to 8 in the 9 cells of the grid, where the index value of leftmost of the first row of the grid has assigned to 0 and the index value of rightmost of the last row of the grid has assigned to 8, and the index values increases from left to right and from bottom to top. The argument win refers to the object of the window drawn on the screen.

• def init_play ( win ): It calls the RNG to choose the first and second player (like a tossing a coin), where the first player will start the game, and it returns the index values of the two players to the main ( ) routine.

• def play ( win, players ): It simulates a single game by alternating between two

players for each step. A game is over when a player ends up of marking three

Tic-Tac-Toe

2

horizontal, vertical, or diagonal cells on the grid; or it’s over when all 9 cells are marked on the grid. For each move, a cell number between 0 to 8 is chosen by the RNG. However, if the cell is chosen before, it calls the RNG to get another cell. The player with index value 0 uses the letter X and the player with index value 1 uses a circle, and places it in the center of the chosen cell. If a player wins a game, then the routine returns the identity of the player to the main ( ) routine, but if the game is a draw, then it returns the value None. After a player makes 3 or more moves in a game, it calls the function after_3_steps ( ) to determine if the player is a winner, and if it’s, it terminates the game.

• def after_3_steps ( n, cell, player): It determines if player is a winner, where n is the

number of moves made by the player and cell is the cell numbers for those n >= 3 moves. To figure out if combinations of 3 out of n cells results a winning: they are located on the same horizontal, vertical, or diagonal positions, it calls the function check_win ( ) for each possible combination: for n = 3, there is only 1 combination, for n = 4, there are 3 combinations, and for n =5, there are 6 combinations. If any one of the possible combinations shows a winning, then it prints the player as a winner and returns the identity of the player to the calling function; otherwise, it returns None.

• def check_win ( f, s, t, cell ): It returns True if the cells in the argument cell with the

index values f, s, and t are in the same horizontal, vertical, or diagonal positions; otherwise, it returns False. For each cell, it computes horizontal and vertical ( x, y ) coordinates on the 3 x 3 grid. If those three cells are on the same row, their x values must be the same, if they are on the same column, their y values must be the same, and if they are on the same diagonal, the absolute value of the difference of their x values must be equal to the absolute value of the difference of their y values.

• def print_stat ( no_wins, no_games ): It prints out the number and percentage of

wins for each player and the number of draws, where no_wins have the winning scores of each player and no_games are the total number of games in the simulation, which are passed by the main ( ) routine.

Name your program as prog4.py and to test it, execute: Make N=4. When the execution is over, the output file prog4.out will contain the output of your program as well as any error messages that might be generated by your program. See the correct output in file prog4.out for 12 games in directory: ~cs503/progs/20f/p4. However, the grid displayed on the terminal screen is not stored in the output file but a demonstration to play the game will be done in a class session. Insert the following lines at the top of your program and make your program executable. #!/usr/bin/python3 from graphics import * # You need this to use the graphical package. from random import seed, randrange # You need this to generate random numbers. To submit the file of your program, execute: mail_prog prog4.py.

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Instant Assignments
Top Academic Tutor
Professional Accountant
Essay & Assignment Help
Top Class Engineers
High Quality Assignments
Writer Writer Name Offer Chat
Instant Assignments

ONLINE

Instant Assignments

I will provide you with the well organized and well research papers from different primary and secondary sources will write the content that will support your points.

$33 Chat With Writer
Top Academic Tutor

ONLINE

Top Academic Tutor

I have read your project description carefully and you will get plagiarism free writing according to your requirements. Thank You

$22 Chat With Writer
Professional Accountant

ONLINE

Professional Accountant

I am an academic and research writer with having an MBA degree in business and finance. I have written many business reports on several topics and am well aware of all academic referencing styles.

$26 Chat With Writer
Essay & Assignment Help

ONLINE

Essay & Assignment Help

I will be delighted to work on your project. As an experienced writer, I can provide you top quality, well researched, concise and error-free work within your provided deadline at very reasonable prices.

$18 Chat With Writer
Top Class Engineers

ONLINE

Top Class Engineers

I can assist you in plagiarism free writing as I have already done several related projects of writing. I have a master qualification with 5 years’ experience in; Essay Writing, Case Study Writing, Report Writing.

$21 Chat With Writer
High Quality Assignments

ONLINE

High Quality Assignments

I find your project quite stimulating and related to my profession. I can surely contribute you with your project.

$35 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

How do i cite the 2014 aca code of ethics - Ocr chemistry pag 5.3 answers - Project part 3 - Philosophy on Behavior Management - Applied Business Software - Guest management system izone - Bio 220 online scavenger hunt for success - Nielsen bases factors for success - Blackpool ice skating club - Aditi property investor million dollar listing - Why can't yeast produce atp anaerobically indefinitely - Perma crete plex seal - The navajo origin legend - Nursing - Teaching projects for nursing students - ISO framework network management - How to apply for mcdonalds franchise - Discussion10 - Oreo slogan twist lick dunk - The spectacular now pdf - Tim hortons target customer - Transition to Graduate Study - Removing conformal coating acetone - 1769 if4 wiring diagram - Important facts about john cabot - International journal of electrical electronics and computers - How to calculate speed of light in diamond - Hay una silla al lado del escritorio en ingles - Sociology - What is a persuasive technique - Advanced lighting technologies inc - Allied merchandisers was organized on may - Https mycampus phoenix edu login asp - Diversification of coca cola - Rectangular prism faces edges vertices - 3 h2o2 molarity - Vietnam market entry decisions case analysis - Which one doesn't belong shapes - Dr etienne du preez - Entrepreneurship theory process practice 4th edition - Week 3 Discussion - Certificate 4 in security operations - Verbs used in objectives - What is a natural ph indicator - What is the service department charge rate for graphics production - APPLICATION OF HEALTH CARE INFORMATION SYSTEMS - The pedlars caravan poem summary - Swanson and associates presently leases a copy machine - Avaya one x agent stuck on connecting - Conch republic electronics case study - What is the gibbs reflective model - Bachelor of actuarial studies handbook - Frank goodnow politics and administration dichotomy - Convert 0.625 into a fraction - Brake shoe identification chart - Issa final exam section 5 case study - Artist of the floating world essay - Aussie batteries and solar maroochydore - Examples of secondary processing - Ben and jerry's homemade case study solution - Baking the Best Cookie (whatever kind you think is best)! (Data Collection Stage) - Volume licensing service centre - Double eyed fig parrot habitat - A piston cylinder device with a set of stops - Society: Mental Health and Welfare - Accounting for Private Versus Public Companies I - 1.21 gv to v - Creative innovative and proactive demeanour - What is presentation expert target - Bharati mukherjee two ways to belong in america - Jacks gully waste management - Sam kant appellate brief - Closing entries are journalized and posted - Hemalogic study worksheet - Realistic investigative artistic social enterprising conventional - Reply to this discussion- Anabel - Analysis of resources and competitive capabilities - How do you graph y 2 3x - What is a positive constant - Discussion #1 - Fortitude piano sheet music - Fortune 100 best companies to work for non union - How mr rabbit was too sharp - Vera bradley case study - Mortgage broker license ontario - 13009 within 24 Hrs - Discussion question - Corporate governance officer job description - Topic 2: Population and Sampling Distributions - Examples of conduction convection and radiation worksheet - Wh questions in past - Which of these lines from the canterbury tales prologue best exemplifies a franklin - 3 phase induction motor with soft start - Iseries mapped drive access denied - Bmw corporate sales program discount - Rewards of factors of production - Grantham university scam - Dental pro 7 reviews - In one reaction mole of sicl - Hornsby height public school