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.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Game Procedures Who does what, where, when, and how?
A Case Study  Some Advice on How to Go about Solving Problems in Prolog  A Program to Play Connect-4 Game.
"Intelligent" CS 5 An object is structured data that is alive, responsible, and intelligent. Sound too friendly? This week’s objects and classes will be.
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.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Tic Tac Toe Prototype Following is a prototype of a Tic Tac Toe program. The main goal of the program is to provide quick and simple entertainment. It.
9-May-15 Notes on Style Testing the TicTacToe game.
CHAPTER 10 FUN AND GAMES Group 1: Xiangling Liu.
Presented by : Ashin Ara Bithi Roll : 09 Iffat Ara Roll : 22 12th Batch Department of Computer Science & Engineering University of Dhaka.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
1 CSE1301 Computer Programming: Lecture 23 Algorithm Design (Part 1)
HW 6: Problems 2&3 Simulating Connect 4.
Intelligent CS 5 ? HW 11 (1 problem !) M/T sections W/Th sections due Sunday, 11/14 at midnight due Monday, 11/15 at midnight Recitation for HW11 -- Friday.
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.
Chapter 7 – Arrays.
Loops For loop for n = [ ] code end While loop while a ~= 3 code end.
THE RENJU GAME BY ABHISHEK JAIN, PRANSHU GUPTA & RHYTHM DAS PCLUB SUMMER PROJECT PRESENTATION JUNE, L7 IIT KANPUR MENTOR – SANIL JAIN.
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
CS 5 Today: two I's AIUI hw11pr2.py an arbitrarily-good Connect 4 player! Player class Extra: scoreBoard4Tourney an intuitive Connect 4 player: hw11pr1.html.
Introduction to TouchDevelop
Indian Institute of Technology Hyderabad SOS - The Game A Project by Paritosh J Chandran Prakhar Bharadwaj Ganesh Mahidhar Nagarjun Srinivasan.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
IS 313 Today Schedule Week 0: Classes Objects You're saying that Python's got class ? Dictionaries and Classes Week 1: Week 2: Where.
Def tomorrow(self): """Changes the calling object so that it represents one calendar day after the date it originally represented. """ if self.month in.
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
IS313 Today: two I's AIUI hw9pr1.py an arbitrarily-good Connect 4 player! Player class Hw 10 (project) I wish there were three i's! Hw 9 is due Wed., 12/23.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
Homework 11 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/14 Mon., 11/15 Problems
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
©2009, Tom McKendree Biplanes ©2009, Tom McKendree.
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
Code Design Using Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
Checkers A Matlab Project by Spenser Davison, Edward Dyakiw, Justin Pezzi, and Scott Wu.
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
2-dimensional Arrays A 2-dimensional array has rows and columns It is actually an “array of arrays” A Tic-Tac-Toe board is an example of a 3 by 3 2-d array.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
CS 115 Lecture 17 2-D Lists Taken from notes by Dr. Neil Moore.
Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems
IS313 Tomorrow… Wednesday, Nov Classes + Objects, part 2 Wednesday, Nov Classes + Objects, part 3 Thursday, Nov Date class due Thursday,
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.
EECS 110: Lec 15: Classes and Objects (2)
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
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.
Introduction To Flowcharting
Sit-In Lab 1 Ob-CHESS-ion
Control Structures
Intelligent CS 5 ? This week's objects will be more adversarial…
This week's classes Connect 4 aiMove
The relational operators
Conditions and Ifs BIS1523 – Lecture 8.

HW 6: Problems 2 & 3 Simulating Connect 4.
HW 6: Problems 2 & 3 Simulating Connect 4.
Tic Tac Toe application
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
EECS 110: Lec 15: Classes and Objects (2)
Presentation transcript:

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 Move = Placing checkers on the board Winning = 4 checkers in a row (vert., horz., diag.) – Move constraints: On top of each other, or Start a new column Problems: Board class (p2), Player class (p3)

Problem 2: Connect 4 Board Variables Board Representation: – Two-dimensional List – Width & height vary (i.e. not just 7x6) Board Class variables – Variable data storing the 2D list – Variable height storing the number of rows – Variable width storing the number of columns

Problem 2: Connect 4 Board Method: Constructor The Constructor __init__ : – Return nothing – Take in the board dimension – Set board height, width, & initialize data elements def __init__( self, width, height ): self.width = width self.height = height self.data = [] for row in range( self.height ): boardRow = [] for col in range( self.width ): boardRow += [' '] self.data += [boardRow]

Problem 2: Connect 4 Board Method: Representation Method __repr__ : Print out the board def __repr__(self): s = '' for row in range(self.height): s += '|' for col in range(self.width): s += self.data[row][col]+'|' s += '\n' #print out separator... (your code here) #print out column numbers... (your code here) return s | | | | | | | |

Problem 2: Connect 4 Board Method: addMove Method addMove : take in column & symbol >>> b = Board(7,5) >>> b.addMove(0, 'X') >>> b.addMove(1, 'O') >>> b.addMove(1, 'X') >>> b.addMove(3, 'O') | | | | | | | | | |X| | | | | | |X|O| |O| | | | def addMove(self, col, ox ): if allowMove(col): # find the first row in # col without a checker... (your code here) # put ox in this position... (your code here)

Problem 2: Connect 4 Board Methods: clear, delMove, allowMove, isFull Method clear(self) : Clear all data to ' ' Method delMove(self, col) : – Opposite of addMove – Delete the top checker of column col – Do nothing if column is empty Method allowMove(self, col) : – False if col is an invalid column number, or full – True otherwise Method isFull(self) checks if the board is full

Problem 2: Connect 4 Board Method: setBoard Method setBoard : take in the string of moves >>> b = Board(7,5) >>> b.setBoard('02353') | | | | | | | | | | | |O| | | | |O| |X|O| |X| | def setBoard(self,moveStr): ch = 'O' for colStr in moveStr: col = int(colStr) if 0<=col<=self.width: self.addMove(col,ch) if ch == 'X': ch = 'O' else: ch = 'X'

Problem 2: Connect 4 Board Methods: winFor Method winFor(self, ox) : – Check if there are 4 ox ’s in a run – Horizontal, vertical, and diagonal – Possible direction: Anchor checkers = checks that may start run Check each of these anchor checkers in 8 directions

Problem 2: Connect 4 Board Methods: hostGame Method hostGame(self) : – Runs until the game ends: A player wins The board is full (draw) – Alternatively ask player 'O' and 'X' to move – Print out the board before asking to move – Invalid move = ask the same player to move again – Valid move = place checker & check for win – At game end report the winner (or tie)

EC Problem 3: Connect 4 Player Overview Goal: Creating an automated player Player class: – Examine the board – Find appropriate move – May look for several moves ahead The variables: At least the following – Character ox – Tie breaking type tbt (either 'LEFT', 'RIGHT' or 'RANDOM', more detail later) – Number of moves ahead ply

EC Problem 3: Connect 4 Player The Essential Methods Construction __init__(self,ox,tbt,ply) Representation __repr__(self) def __init__( self, ox, tbt, ply ): self.ox = ox self.tbt = tbt self.ply = ply def __repr__( self ): s = 'Player for ' + self.ox + '\n' s += 'with tiebreak type: ' + self.tbt + '\n' s += 'and ply == ' + str(self.ply) + '\n\n' return s

EC Problem 3: Connect 4 Player The Required Methods Opposite character oppCh(self) : – Returns 'X' if own character is 'O', vice versa Evaluating Board scoreBoard(self, b) : – Given a board b, return 100.0, 50.0 and 0.0 respectively for win, tie, and lose situation Tie-breaking: tiebreakMove(self, scores) : – Score = list of floating point – Returns the column with the highest score – Multiple highest score: select one based on tbt – Example: tiebreakMove([0,50,0,50]) returns 1 if self.tbt == ‘LEFT’

EC Problem 3: Connect 4 Player The Brain: scoreFor Returns a list of scores: – The c th score = goodness after a move to column c – Goodness = what happens after self.ply moves Using recursion: – Base case 1: A full column = score of -1.0 – Base case 2: 0-ply = state of the game right now (hence, all non-full columns have the same score) – Base case 3: Game-over = state of the game right now – Recursive case: Make a move into a corresponding column, change the (local) board, evaluate recursively

0-ply scores for O : col 0col 1col 2col 3col 4col 5col 6 1-ply scores for O: col 0col 1col 2col 3col 4col 5col 6 2-ply scores for O : col 0col 1col 2col 3col 4col 5col 6 3-ply scores for O : col 0col 1col 2col 3col 4col 5col b ‘X’ ‘O’ EC Problem 3: Connect 4 Player

EC Problem 3: Connect 4 Player Put them all together Choose the next move: nextMove(self,b) : – Return the best column to move to – Wrapper method (heavy lifting is already done) Play the game playGame(self,px,po) : – Modify hostGame from the Board class – Instead of getting user input, it use moves getting from px and po alternatively – Additional twist: if one of px and po is a string human, then get the input from the user instead