CPE 101 Project 3 Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Tic-Tac-Toe Simulator

 

Your code must pass all of the tests to get any credit. Your grade will be based on the date which your code passes all the tests. To get 100% credit for this project, you must submit in PolyLearn by 11:00PM on 5/9/18. Code that does not pass all of our tests will not get any credit.

 

Monday      (5/9) – 100% @ 11:00PM

Tuesday      (5/10) – 80%  @ 11:00PM

Wednesday (5/11) – 60%  @ 11:00PM

 

Objectives:

 

  • Practice on List
  • More practice on writing loops in python.
  • More practice on writing and calling functions that you have written.
  • Practice testing your code.
  • To appreciate the benefits of modular development.

 

Required File Header:

All students are required to have the following header comment at the top of their source files. Note that the stuff to the right of the colon in red is information for an imaginary example student. (Please put YOUR appropriate information. Also, your header comment is not expected to have red text.) All program files require this header.

 

# Project 3 – Tic-Tac-Toe Simulator

# Name: Your Name

# Instructor: S. Einakian

# Section: Your Section

 

Resources:

  • Your instructor, via office hours, email, etc.
  • Free tutoring Sunday-Thursday, 7-9 PM, 14-302
  • Your TA

 

Program Description:

For this program, you will be writing a simulation for the game, Tic-Tac-Toe. Two people play Tic

Tac Toe with paper and pencil. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of their marks on the board in a row, column or one of the two diagonals, they win. When the board fills up with neither player winning, the game ends in a draw.

This program has two parts:

  1. Two Players
  2. Play with Computer

Part One: Two Players

  • Take user input (for two players)
  • Store user inputs into a 3×3 Tic-Tac-Toe board
  • Check for validity of inputs (no overriding, proper cell value, etc.)
  • Check for a win every turn
  • Print the board every turn

 

Part Two: With Computer

  • Randomly pick a player (you or computer)
  • Take input (for one players)
  • Computer or you will generate the next
  • Store user inputs into a 3×3 Tic-Tac-Toe board
  • Check for validity of inputs (no overriding, proper cell value, etc.)
  • Check for a win every turn
  • Print the board every turn

 

Getting Player Input:

  • Each player will input a number (1-9) which corresponds to the following cells.
1 2 3
4 5 6
7 8 9

 

  • Location 0 in list corresponds with number 1
  • Players’ input will be stored in a list.
  • Players will take turns.

 

Checking For a Win:

  • A player wins if there is a sequence of 3 of the same letter in the same row, column, or diagonal.

 

Printing Output:

  • You should use for loops to output a 3×3 board.

 

General Notes:

  • You should implement your functions in a file, py ï‚· Checking for a win requires multiple operations.

 

 

Functions:

  1. Welcome
    1. Welcomes user to the game and explain the game rules.
    2. You will provide your own Welcome information
    3. Ask user to decide if playing with computer (pass 1) or another player (pass 2)
    4. No parameter to pass
    5. Return 1 if play with computer and 2 if plays with another player

 

  1. createBoard
    1. You will use a list to store the data
    2. List has 9 items starting from index 0 to 9 which holds the values (X or O)
    3. This function has no parameter to pass and it return a list
    4. Your game board at first should look like the following:

 

1   |   2  |   3

—————

4   |   5  |   6

————— 7   |   8  |   9

 

  1. printBoard
    1. The printBoard function will print the game. Remember that the board is represented as a list of nine strings, where the string at index 0 is the mark on space 1 on the Tic Tac Toe board, and so on.
    2. Passing a list as the board to the function.
    3. The first call to the print will show an empty board game:

 

|      |

—————

|      |

—————

|      |

 

  1. pickLetter
    1. This function ask user to pick ‘X’ or ‘O’
    2. No parameter to pass
    3. This will return the letter of player’s choice
    4. If user enters the wrong letter you need to ask user to reenter the letter
    5. This function return letter

 

  1. getInput
    1. This function takes the letter and board as parameters
    2. Ask user to enter the letter of his/her choice in the one of the locations (1-9) on the board
      1. Where do you like to place your letter (pick in range of 1-9)
      2. If user repeat the location or pass value outside range (1-9) for placing the letter:
      3. Send a message:
      4. Invalid move! Location is already taken. Please try again.
    3. This function will return the board after entering the letter

 

  1. checkRows
    1. takes the board as parameter
    2. returns True and the letter if a row is filled with the same Letter

 

  1. checkCols
    1. takes the board as parameter
    2. returns True and the letter if a column is filled with the same Letter

 

  1. checkDiags
    1. takes the board as parameter
    2. returns True and the letter if any of diagonals are filled with the same Letter

 

  1. boardFull
    1. takes the board as parameter
    2. returns True if the board is full

 

  1. checkWin
    1. takes the board
    2. if any of checking (rows, columns, diagonals ) returns True
    3. announce the winner
    4. if board is filled and no winner announce draw!

 

  1. turnCount

Use this function to show, which turns the game is. Example:          It’s Player 2’s (O’ )turn!

 

  1. takes count of turns
  2. increment counter
  3. return counter

 

 

 

 

 

Resources:

 

You can download the following files from PolyLearn:

  • py, at least 2 test cases for each function
  • py
  • incol (test file for two player)
  • inrow (test file for two player)
  • india (test file for two player)

For testing your program with these files:

python3 tictactoe.py < incol        python3 tictactoe.py < inrow

python3 tictactoe.py < india

 

 

Note:

You can add any extra functions you need. You have freedom on how you format your messages. Make sure to follow the steps. The sample screenshot is given.

USE EXACTLY THE SAME FUNCTIONS’ NAME.

 

Submission:

  • py (test all your functions- at least two tests for each function)
  • py
  • py

 

Rubric:

  • py (implement all functions) 5 Points
  • py (call all necessary functions) 5 Points
  • py (two test for each function) 10 Points
  • pass 7 tests                                                 70 Points
  • comments                                                 10 Points

 

 

 

  • Project3-rsv0gr.zip