HW 6: Problems 2 & 3 Simulating Connect 4.

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

Game Procedures Who does what, where, when, and how?
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.
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.
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.
CHAPTER 10 FUN AND GAMES Group 1: Xiangling Liu.
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.
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.
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.
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.
Loops For loop for n = [ ] code end While loop while a ~= 3 code end.
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
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.
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.
Homework 11 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/14 Mon., 11/15 Problems
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
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!
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.
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.
Checkers A Matlab Project by Spenser Davison, Edward Dyakiw, Justin Pezzi, and Scott Wu.
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.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
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,
EECS 110: Lec 15: Classes and Objects (2)
Python programming - Defining Classes
Intro to Computer Science II
A fun reading Comprehension Game
IF statements.
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
2-D Lists Taken from notes by Dr. Neil Moore
Multi-dimensional Array
Control Structures
Intelligent CS 5 ? This week's objects will be more adversarial…
Problem Solving and Programming CS140: Introduction to Computing 1 8/21/13.
The relational operators
Search in OOXX Games J.-S. Roger Jang (張智星) MIR Lab, CSIE Dept.
EECS 110: Lec 10: Definite Loops and User Input
Conditions and Ifs BIS1523 – Lecture 8.

HW 6: Problems 2 & 3 Simulating Connect 4.
Minimax strategies, alpha beta pruning
Tic Tac Toe application
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Beginning C Lecture 5 Lecturer: Dr. Zhao Qinpei
EECS 110: Lec 15: Classes and Objects (2)
2-D Lists Taken from notes by Dr. Neil Moore
Minimax strategies, alpha beta pruning
Tic-Tac-Toe Game Engine
Backtracking, Search, Heuristics
2019 SAIMC Puzzle Challenge General Regulations
Unit II Game Playing.
Data Structures & Programming
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 | | | | | | | | --------------- 0 1 2 3 4 5 6 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 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| | | | --------------- 0 1 2 3 4 5 6 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

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| | --------------- 0 1 2 3 4 5 6 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': 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 cth 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

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

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