Tic Tac Toe application

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

Tic tac toe v1.2 Made by Rogonow XX PC: X YOU: O The PC-player with mark X goes first. After the PC, you place the mark O at the position of a green oval.
By Michael Coco. Setting up the board  Two dimensional array board[x][y]  First column second row is 10  Walls will be labeled with 2  Open positions.
Tic-Tac-Toe Using the Graphing Calculator for Derivatives.
Computers playing games. One-player games Puzzle: Place 8 queens on a chess board so that no two queens attack each other (i.e. on the same row, same.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. It is common to use two nested loops when filling or searching: for.
Chapter 13 ARRAY LISTS AND ARRAYS. CHAPTER GOALS To become familiar with using array lists to collect objects To learn about common array algorithms To.
Chapter 13 ARRAY LISTS AND ARRAYS CHAPTER GOALS –To become familiar with using array lists to collect objects –To learn about common array algorithms –To.
Playing Tic Tac Toe with Neural Networks Justin Herbrand CS/ECE/ME 539.
Tic Tac Toe Game Design Using OOP
TIC-TAC-TOE FELIX CHEN CLUSTER 5: Computers in Biophysics and Robotics.
PLANNING THE TIC TAC TOE GAME BY NEEL DAVE. TIC TAC TOE INSTRUCTIONS Tic Tac Toe Instructions The basic concept of Tic Tac Toe 1.This is a game for two.
Conditionals Lab Dan Maselko. Overview  Gain familiarity with working with conditionals  Become familiar with using the modulus operator  Understand.
J AVA A SSIGNMENT 1. O VERVIEW Tic Tac Toe How it should work Using the supplied methods What you need to do How we will test your code.
Presented by : Ashin Ara Bithi Roll : 09 Iffat Ara Roll : 22 12th Batch Department of Computer Science & Engineering University of Dhaka.
Integer Tic Tac Toe Let’s Begin Rules: 1.Erase all x’s and o’s from the previous game before you begin. 2.Decide which player will be x’s and which will.
1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)
Representing a Game Board In a game, we represent the action taking place using an array – In a very simple game, we use individual variables to represent.
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo.
Loops For loop for n = [ ] code end While loop while a ~= 3 code end.
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
1 CSE1301 Computer Programming: Lecture 24 - Supplement Teddy’s Modules.
Artificial Intelligence and Robotics By Keith Bright & John DeBovis.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
TIC TAC TOE. import java.util.Scanner; import java.util.Random; public class PlayTTT{ public static void main(String[]args){ Scanner reader = new Scanner(System.in);
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Mining Presentation (Sedimentary Group) Read through the following slides carefully! *When you see a Stop and DISCUSS the question with your partner!
HW 6: Problems 2 & 3 Simulating Connect 4. HW 6: Overview Connect 4: Variation of Tic-Tac-Toe – Board: Vertical 7x6 – Two players take alternating move.
Natural Language to Machine Readable Format By: Damian Tamayo Presentation 2 – Nov. 13, 2009 CIS 895 – MSE Project.
Tic tac toe specifications Maaike Gerritsen Ingmar van der Steen Bas Geertsema Brian Vermeer.
Discussion 7. Make up tutorial Official make up slot: Friday 27 Oct (4-6) (by majority of the people that send me the ) For those who cannot make.
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
1 Data Structures CSCI 132, Spring 2014 Lecture 18 Recursion and Look-Ahead.
Tic tac toe XX PC: X YOU: O The PC-player with mark X goes first. After the PC, you place the mark O at the position of a green circle. If you succeed.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Tic – Tac – Toe ! Choose a square by clicking on “box #” Choose a square by clicking on “box #” If the person choosing the square gets the problem correct,
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
Repetitive Structures
CSC111 Quick Revision.
while Repetition Structure
Chapter 8 – Arrays and Array Lists
Intro to Computer Science II
Next Level Tic-Tac-Toe
Arrays 1. One dimensional arrays - Review 2. Using arrays
multi-dimensional arrays
O X X O O X X O X O X O O X O X O X Tic Tac Toe Graphical
Lesson 5 Functions I A function is a small program which accomplishes a specific task. For example, we invoke (call) the function, sqrt(x), in the library.
Tic – Tac – Toe ! Choose a square by clicking on “box #”
IPad Center.
Sit-In Lab 1 Ob-CHESS-ion
The "8 Queens" problem Consider the problem of trying to place 8 queens on a chess board such that no queen can attack another queen. What are the "choices"?
Multi-dimensional Array
Review.
Problem Solving and Programming CS140: Introduction to Computing 1 8/21/13.
Looping.
Control Structure Senior Lecturer
DIVIDING FRACTIONS TIC-TAC-TOE
Patterns to KNOW.
Announcements & review
HW 6: Problems 2 & 3 Simulating Connect 4.
HW 6: Problems 2 & 3 Simulating Connect 4.
Continue with Life, Magic and Catch -up
Two dimensional arrays.
The "8 Queens" problem Consider the problem of trying to place 8 queens on a chess board such that no queen can attack another queen. What are the "choices"?
Tic-Tac-Toe Game Engine
Two dimensional arrays.
Data Structures & Programming
Presentation transcript:

Tic Tac Toe application

TicTacToe application Write a program to simulate the tic tac toe game. The program should have the following functions. startOver(): empty all the cells. makeMove(char player): prompt user for a row and column # and mark the cell with ‘X’ or ‘O’. displayBoard(): display the board with related marked ‘X’ or ‘O’. winner(): return the winner ‘X’ or ‘O’

Remarks What is the control condition for the game to continue? As long as no winner yet(3 ‘X’ or ‘O’ in a row) The board is not fully occupied. How to determined this? Whenever there is a valid move, counter increments, the maximum moves=9 What is a valid move? Within row and column range Is not occupied

[ ] [ ] [ ] enter row #: 0 enter column #: 0 [ X ] [ ] [ ] [ ] [ ] [ ] enter row #: 0 enter column #: 0 [ X ] [ ] [ ] enter row #: 1 enter column # : 1 [ ] [ O] [ ]

Tic Tac Toe pseudo code startOver(); do{ displayBoard(); makeMove(current player); moves counter ++; }while (moves counter <=9 and winner() == ‘ ‘); display Winner;

Winner for(row=0; row<TTT.length; row++) if (cell[row][0] == cell[row][1] && cell[row][1] == cell[row][2] && cell[row][0] != ‘ ‘ ) return cell[0][0]; for(col=0; col<TTT[0].length; col++) If (cell[0][col] == cell[1][col] && cell[1][col] == cell[2][col] && cell[0][col] != ‘ ‘ ) return cell[0][col]; 0 1 2 O X 1 2

Winner //test diagonal if (cell[0][0] == cell[1][1] && cell[1][1] == cell[2][2] && cell[0][0] != ‘ ‘ ) return cell[0][0]; if (cell[0][2] == cell[1][1] && cell[1][1] == cell[2][0] && cell[0][2] != ‘ ‘ ) return cell[0][2]; 0 1 2 O X 1 2

Make a move Declare a scanner object; valid move flag = false; do{ get row and col input from user; if(row and col are valid && cell[row][cell]=‘ ‘) {mark the cell; valid move flag = true; } else { valid move flag=false; prompt user for new input;} }while (valid move flag = false)