is313 … monday, nov. 8 - classes + objects, part 2 monday, nov. 15 - project strategies &...

163
IS313 Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov. 16 - Board class due & proj. idea Monday, Nov. 22 - UIs & another example presentation Wed., Dec. 1 - preliminary report due – with code Monday, Dec. 6 - In-class project presentations Tuesday, Dec. 7 - intermediate report – with code Monday, Dec. 13 - no class meeting, but I'll be available... Thursday, Dec. 17 - Final project due! Final HW IS 313 Schedule Final Project Tuesday, Nov. 23 - no HW due Monday, Nov. 29 - no class meeting (conference)

Upload: corey-ferguson

Post on 04-Jan-2016

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

IS313 …

Monday, Nov. 8 - Classes + Objects, part 2

Monday, Nov. 15 - Project strategies & example pres.

Tuesday, Nov. 9 - Date class due

Tuesday, Nov. 16 - Board class due & proj. idea

Monday, Nov. 22 - UIs & another example presentation

Wed., Dec. 1 - preliminary report due – with code

Monday, Dec. 6 - In-class project presentations

Tuesday, Dec. 7 - intermediate report – with code

Monday, Dec. 13 - no class meeting, but I'll be available...

Thursday, Dec. 17 - Final project due!

Final HW

IS 313 Schedule

Final Project

Tuesday, Nov. 23 - no HW due

Monday, Nov. 29 - no class meeting (conference)

Page 2: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

AI: Artificial Intelligence

Monday, Nov. 8 - Classes + Objects, part 2

Monday, Nov. 15 - Project strategies & example pres.

Tuesday, Nov. 9 - Date class due

Tuesday, Nov. 16 - Board class due & proj. idea

"High-level AI"

Game-playingNatural Language

TranslationTask planning

"Low-level AI"

RoboticsSensing and reacting

Computer visionAdapting to human actions

Page 3: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Low-level AI

"Low-level AI"

RoboticsSensing and reacting

Computer visionAdapting to human actions

What's difficult/ easy here?

Page 4: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

IS313: software intelligence

An object is structured data that is alive, responsible, and intelligent.

Sound too friendly?

This week’s objects and classes will be just the opposite ...

X to move.

Is there a way to win?

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X|O| |--------------- 0 1 2 3 4 5 6

import antigravity!

Page 5: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Aargh!

Python has no Connect-four datatype…

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X|O| |--------------- 0 1 2 3 4 5 6

Can I see a demo?

… but we can correct that!

Page 6: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Designing classes

1) What data? (Data Members)

2) What are the key capabilities? (Methods)

Not limited to 7x6!

Page 7: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

BoardB

intwidthstr str str

str str str

str str str

datalist str

str

str? int

height

What is the name of the method that will construct this data?

Starting from B, how would you examine the string marked by the ?

3

4

Page 8: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: constructor

class Board: """ a datatype representing a C4 board with an arbitrary number of rows and cols """ def __init__( self, width, height ): """ the constructor for objects of type Board """ self.width = width self.height = height self.data = [] # this will be the board self.data = [ [' ']*self.width ] * self.height

Doesn't work! Not much of a game…

Page 9: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: constructor

class Board: """ a datatype representing a C4 board with an arbitrary number of rows and cols """ def __init__( self, width, height ): """ the constructor for objects of type Board """ self.width = width self.height = height self.data = [] # this will be the board for row in range( self.width ): boardRow = [] for col in range( self.height ): boardRow += [' '] # add a space to this row self.data += [boardRow]

Better! Same idea as in Life

Page 10: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: constructor

class Board: """ a datatype representing a C4 board with an arbitrary number of rows and cols """ def __init__( self, width, height ): """ the constructor for objects of type Board """ self.width = width self.height = height self.data = [] # this will be the board self.data = [ [' ']*self.width for row in range(self.height) ]

Even shorter!

What was this called again… ?

Page 11: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

Boardb

intwidth

str str str

str str str

str str str

datalist

str

str

str

intheight

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 6

67

X O O O

X X

X

……

printed version

Which rows and columns are these?

which is row 0 ?

Page 12: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The grim task of printing …

Boardb

intwidth

str str str

str str str

str str str

datalist

str

str

str

intheight

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 6

What is the name of the method that will print this data?

6

7

X O O O

X X

X

……

Which rows and columns are these?

Page 13: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def __repr__(self): """ this method returns a string representation for an object of type Board """ s = '' for row in range( self.height ): s += '|' for col in range( self.width ): s += self.data[row][col] + '|' s += '\n'

return s

Connect Four: __repr__

What else?

Page 14: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

>>> b = Board( 7, 6 )

>>> print b

>>> LoS = [ ' ', ' ', 'OXO ', 'XXOO ', 'XOXXOX ', 'XOOXXOO' ]

>>> b.set_board( LoS )

>>> print b

Connect Four: set_board

| | | | | | | || | | | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

| | | | | | | || | | | | | | || | | | | | | || | | | | | | || | | | | | | || | | | | | | |--------------- 0 1 2 3 4 5 6

What is this a list of?

Page 15: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def set_board(self, LoS): """ this method sets the board to the list_of_strings that is input """ for row in range( ):

for col in range( ):

self.data[row][col] = LoS[row][col]

Connect Four: set_board

What goes in the blanks?

Page 16: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Try it!

def addMove(self, col, ox):

row = self.height-1 while True: if self.data[row][col] == ' ': self.data[row][col] = ox

row -= 1

Step through this addMove method.

How does it work?

What's wrong?

Try to fix it… !

a C4 board

col #'O' or 'X'

| | | | | | | || | | | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

Page 17: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Try it!def allowsMove(self, col):

a C4 board col #

allowsMove should return True if col has enough space

to allow a move; it should return False otherwise.

| |X| | | | | || |O| | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

b

b.allowsMove(0)

b.allowsMove(1)

True

False

Page 18: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

C4 Board class: methods

__init__( self, width, height )

allowsMove( self, col )

__repr__( self )

addMove( self, col, ox )

isFull( self )

winsFor( self, ox )

the “constructor”

checks if allowed

places a checker

outputs a string

checks if any space is left

checks if a player has won

hostGame( self )play!

delMove( self, col )removes a checker

What will require the most thought?

set_board( self, LoS )sets the board arbitrarily

Page 19: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Checking wins… ?

Thoughts?

X O

self

corner cases?

Page 20: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two-player games have been a key focus of AI as long as computers have been around…

Strategic thinking == intelligence?

In 1945, Alan Turing predicted that computers

would be better chess players than people in

~ 50 years…

and thus would have achieved intelligence.

Alan Turing memorial Manchester, England

Page 21: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

500

1200

2000

2800

Computer Chess

early programs ~ 1960’s

Computers cut their teeth playing chess…

Ranking

beginner

amateur

world ranked

world champion

MacHack (1100) ~ 1967 MIT

Deep Thought ~ 1989 Carnegie Mellon

Slate (2070) ~ 1970’s Northwestern

Deep Blue ~ 1996 IBM

Deep Blue rematch ~ 1997 IBM

100’s of moves/sec

10,000’s of moves/sec

1,000,000’s moves/sec

3,500,000 moves/secDeep Fritz: 2002X3D Fritz: 2003 Hydra: 2006

200,000,000 moves/sec

first paper: 1950

What is Hydra's chess rating?

Page 22: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

How humans play games…

- experts could reconstruct these perfectly - novice players did far worse…

An experiment (by A. deGroot) was performed in which chess positions were shown to novice and expert players…

Page 23: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

How humans play games…

- experts could reconstruct these perfectly - novice players did far worse…

Random chess positions (not legal ones) were then shown to the two groups

- experts and novices did equally well (badly) at reconstructing them!

An experiment (by A. deGroot) was performed in which chess positions were shown to novice and expert players…

Page 24: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two-player games have been a key focus of AI as long as computers have been around…

Strategic thinking == intelligence?

humanscomputers

good at evaluating the strength of a board for a player

good at looking ahead in the game to find

winning combinations of moves

… humans and computers have different relative strengths in these games.

hw9 pr1

building an AI chess playeremulating a human by

evaluating a board position

ex. credit

Page 25: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Computer Chess…

Page 26: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoreBoard(self,b) ‘X’‘O’

Assigns a score to any board, b

100.0 50.0 0.0A simple system:for a win for a lossfor anything else

Score for Score for

Score for Score for

Page 27: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead…

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are

there to consider?

0-ply

1-ply

A 1-ply lookahead player will "see" an impending victory.

turn

A score for each

column…?

scores

p42.scoresFor( b42 )

special case

Page 28: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two moves ahead… ?

A 2-ply lookahead player will also "see" an opponent's

impending victory.

's

What about 3-ply?

2-ply

1-ply score

score

turn

Page 29: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Difficulty == Branching Factor

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

• On average, there are fewer than 40 possible moves that a chess player can make from any board configuration… 0 Ply

1 Ply

2 Ply

Hydra at home in the United Arab Emirates…

Hydra looks ahead 18 ply !

Page 30: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

1 Ply

2 Ply

Boundaries for qualitatively

different games…

0 Ply

Page 31: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

“solved” games

computer-dominated

human-dominated

1 Ply

2 Ply

0 Ply

Progress

Page 32: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov
Page 33: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hwks and Projects

• Extra: A Connect Four Player…

• Homework 8: A Connect Four Board… due 11/16/10

ok anytimewell, by the end of the term…

Page 34: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hwks and Projects

• Homework 8, part 0: final project proposal

Pre-planned projects Ideas Open-ended

4) robot navigation: pyRobot

2) 3d simulation game: vPool

1) Web-based Text Clouds

3) implementing Picobot!

Flash Cards ?

pySQL ?

Image processing

using pyGame: "snake"

others welcome!

• Extra: A Connect Four Player…

• Homework 8: A Connect Four Board… due 11/16/10

ok anytimewell, by the end of the term…

Low-level computation?

Page 35: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Project Deliverables

• Proposal due 11/16/10

• Preliminary milestone due 12/1/10

one-page (proposal.txt) that includes your project choice and a first description of the project-specific ideas - also, what libraries you'll use

https://www.cs.hmc.edu/twiki/bin/view/CS5/ISProjectsPage

Working code (preliminary.zip) that uses your libraries and shows access to the data you need (sound, graphics, etc.) Also, a plan for the next steps to take – initial functions and/or classes you plan to build.

• Presentation / intermediate milestone due 12/6 & 12/7The presentation is ~10 minutes of your vision, the technical details, and a demo of what you have so far. The intermediate.zip milestone should have the presentation, demo, and a final plan, including classes.

• Project due 12/17/10Your final project (project.zip), with documentation and "future work."

Page 36: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Project ideas: sales pitches

from well-defined to open-ended...may help fill in existing ideas...

Page 37: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hey! Watch where you're going!

The pyRobot project

Goal: get from Pt A to Pt B2d Roomba simulator

How do I control this robot !?!

Pt B

Pt A

Page 38: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The pyRobot project

Robot control continuously runs three things:

SENSE

[x,y,thd], bump = self.getData()

while True:

Page 39: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The pyRobot project

Robot control continuously runs three things:

SENSE PLAN

[x,y,thd], bump = self.getData()

if bump[0] == True or bump[1] == True: print 'BUMP!', print ' [Left bump sensor:', bump[0], '] ', print ' [Right bump sensor:', bump[1], '] ' robotTask = STOP

STOP is one of the robot's states. Every 40th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep!

while True:

Page 40: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The pyRobot project

Robot control continuously runs three things:

SENSE PLAN ACT

[x,y,thd], bump = self.getData()

if bump[0] == True or bump[1] == True: print 'BUMP!', print ' [Left bump sensor:', bump[0], '] ', print ' [Right bump sensor:', bump[1], '] ' robotTask = STOP

STOP is one of the robot's states. Every 40th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep!

if robotTask == STOP: self.setVels(0,0) robotTask = KBD

while True:

Page 41: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Maps are set at the very bottom of the main.py file:

Required

Extra

Page 42: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

PicoRoomba!

The pyRobot project ~ additions

Goal: get from Pt A to Pt B

Start in an unknown location on the map…

Optional

Use only the bump sensors… (no range sensing)

Implement a niftier interface…

Use noisy (realistic) data

Main

vPython Roomba?

ASCII Roomba?

Page 43: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

PicoRoomba!

The pyRobot project ~ additions

Goal: get from Pt A to Pt B

Start in an unknown location on the map…

vPython Roomba?

ASCII Roomba?Use only the bump sensors… (no range sensing)

Implement a niftier interface…

Try it out on a Roomba…

Use noisy (realistic) data

Optional

Main

Page 44: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Let’s play!

I’ll take your cue.

3d simulator, VPython

The vPool project

Page 45: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The vPool project

VPython?Easily installable for windows…

Also installable on the Mac…- it is on the Macs in the CS lab…

A simple example:

from visual import *

c = cylinder()

What's visual?

What's c?

at least it's not Visual C…

www.vpython.org

- Not really installable under Linux

Page 46: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The vPool project

from visual import *

floor = box( pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)

ball = sphere( pos=(0,4,0), radius=1, color=color.red)

ball.velocity = vector(0,-1,0)dt = 0.01

while True: rate(100) ball.pos = ball.pos + ball.velocity*dt

if ball.y < ball.radius: ball.velocity.y = -ball.velocity.y else: ball.velocity.y = ball.velocity.y - 9.8*dt

How many classes?

How many objects?

data members?

What's the if/else

doing?

Page 47: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The vPool project

Phunky Fisicks is welcome!

Collisions with walls?

Collisions with other pool balls?

Pockets?

A few examples to get you thinking…

Linux users are welcome!

But they should use another OS…

Page 48: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Picobot returns!

Page 49: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Picobot is a finite-state machine!

Basic idea: implement Picobot (the homework problem from Week 1)

Requirements:

The Picobot project

Text and graphical output

Read Picobot program from a file

Read maze description from a file

Track visited/unvisited squares

Prohibit illegal moves

Page 50: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Current State: 1

Current Rule: 1 N*W* -> X 2

+++++++++++o++o+o++++oooooo ++++++o++ ++oooo+++++++++o ++oooo+++ +++++o++++++Rooo +++++++++++

The Picobot project

First, prototype it as ASCII-bot

Picobot started here…

and is now here…

Page 51: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

• Text and graphical output• Read Picobot program from a file• Read maze description from a file• Track visited/unvisited squares• Prohibit illegal moves• Stop when maze completely visited

The Picobot project

Required capabilities:

Page 52: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The Picobot project

• Choice of graphical packages • vpython• turtle• csplot/csgrid (Game-of-Life)

• Start/stop/step feature• Maze editing• Pebble dropping• Be inventive!

csplot or csgrid version…Graphical picobot:

Lots of options…

Page 53: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hey! Picobot in 3d…

Mine's going to be in 5d!

The Picobot project

Page 54: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

tag cloud'07

?

Page 55: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

text cloud

Summary of the words in a body of text, sized and painted according to their frequency.

this doesn't look nearly colorful enough…

Page 56: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

From text…

… to cloud

1. Start with entered webpage (URL)

2. Read in text

3. Create list of words out of text

4. "Clean" the words

5. "Stem" the words

6. Count the words

7. Return a string with frequencies

8. Add advanced features…

Huh?

Page 57: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

http://www.cs.hmc.edu/~cs5grad/cs5/textcloud/page1.html

Spamming spammers spammed spam. Spam spam spam! I love spam!

['spamming', 'spammers', spammed', 'spam.', 'spam', 'spam', 'spam!','I', 'love', 'spam!', 'page', '2']

Page 2

Page 58: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

http://www.cs.hmc.edu/~cs5grad/cs5/textcloud/page1.html

Spamming spammers spammed spam. Spam spam spam! I love spam!

['spamming', 'spammers', spammed', 'spam', 'spam', 'spam', 'spam','love', 'spam', 'page', '2']

['spamming', 'spammers', spammed', 'spam.', 'spam', 'spam', 'spam!','I', 'love', 'spam!', 'page', '2']

Page 2

What changed here?

Page 59: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

http://www.cs.hmc.edu/~cs5grad/cs5/textcloud/page1.html

Spamming spammers spammed spam. Spam spam spam! I love spam!

['spamming', 'spammers', spammed', 'spam', 'spam', 'spam', 'spam','love', 'spam', 'page', '2']

['spamming', 'spammers', spammed', 'spam.', 'spam', 'spam', 'spam!','I', 'love', 'spam!', 'page', '2']

['spam', 'spam', spam', 'spam', 'spam', 'spam', 'spam','love', 'spam', 'page', '2']

Page 2

What changed here?

What next?

Page 60: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

Suggested Approach: Develop the basic application the usual way, using IDLE.

• Once you have everything working,

transfer your files to your webspace.

set up the HTML wrapper files & go…

Hypertext Markup Language

• Use the provided code to read HTML

• Personalize - There are lots of ways to do this!

• Once you have things working, move on to writing HTMLfollowing links beyond depth 1avoiding repeated links!

• Make sure that you can process the files appropriately into ordered lists of words…

Page 61: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text-cloud historyhttp://chir.ag/phernalia/preztags/

Page 62: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Other ideas...

Low-level computation ~ circuits ?

Javascript? ~ flash cards ? maps ?

Images? ~ online salon ? illusions ?

Page 63: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Let me know!

Hw8 part 1: A Connect Four Board

Hw8 part 0: project idea and proposal

Page 64: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov
Page 65: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Player data

PlayerpForX

What data does a computer AI player need?

Let's see a demo!

stringox

stringtbt

'X' 'LEFT'intply

0

DATA MEMBERS

tiebreakTypechecker, O or X moves to look ahead

surprisingly little!

How about knowledge about its opponent?

Page 66: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Player

Player methods

__init__(self, ox, tbt, ply)

__repr__(self)

scoreBoard(self, b)

scoresFor(self, b)

tiebreakMove(self, scores)

nextMove(self, b)

oppCh(self)

Board

__init__( self, width, height )

allowsMove( self, col )

__repr__( self )

addMove( self, col, ox )

isFull( self )

winsFor( self, ox )

hostGame( self )

delMove( self, col )

Page 67: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoreBoard

Assigns a score to any board, b

100.0 50.0 0.0A simple system:for a win for a lossfor anything else

scoreBoard(self, b)

Implementation ideas…

What methods that already exist will come in handy?

This doesn't seem to be looking very

far ahead !

How can there be no 'X' or 'O' input?

What class is this method in?

Page 68: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoresFor

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are there to consider?

0-ply

1-ply

scoresFor( self, b ) returns a LIST of scores, one for each column you might choose to move next…

2-ply

Page 69: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

b

0-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

1-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

2-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

3-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

"Quiz" 'X'

'O'you - or self - is

playing 'O'

Name(s):

Fill in the N-ply score for a move to each column. The same move is evaluated at each ply! It's just evaluated farther into the future.

Looks 0 moves into the future

Looks 1 move into the future

Looks 2 moves into the future

Looks 3 moves into the future

Page 70: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

| | | | | | |O|| | | | | | |O|| | | | | | |X||X| |X|O| | |O||X|O|O|X| |X|X||X|O|O|O| |O|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

It is X’s move. What scores does a 2-ply lookahead for X assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

Which change at 3-ply?

Which change at 2-ply?

Example 1-ply and 2-ply lookahead scores

Page 71: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

| | | | | | |O|| | | | | | |O|| | | | | | |X||X| |X|O| | |O||X|O|O|X| |X|X||X|O|O|O| |O|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

It is X’s move. What scores does a 2-ply lookahead for X assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

be careful!

-1 100

50 100

50 100

50

100

0 0 0 50 0 -1

Which change at 2-ply? 0 0

Which change at 3-ply?100

Answers to example lookahead scores

Page 72: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b

scoresFor each column

(1) For each possible move

(2) Add it to the board

Page 73: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

(self) 'X'

'O'

new 'X'

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT its scoresFor each board!

At what ply?

[50,50,50,50,50,100,50]

[ 0, 0, 0, 0, 0, 0, 0 ]

scoresForneeds to return a list of 7 numbers for self

these are all of the opponent's evaluations of its next move…

[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]

[50,50,50,50,50,50,50]

[50,50,50,50,50,100,50]

Page 74: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

(self) 'X'

'O'

new 'X'

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT its scoresFor each board!

At what ply?

[50,50,50,50,50,100,50]

[ 0, 0, 0, 0, 0, 0, 0 ]

scoresForneeds to return a list of 7 numbers for self

these are all of the opponent's evaluations of its next move…

[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]

[50,50,50,50,50,50,50]

[50,50,50,50,50,100,50]

What score does the opponent give

each?

Page 75: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

(self) 'X'

'O'

new 'X'

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT its scoresFor each board!

At what ply?

[50,50,50,50,50,100,50]

[ 0, 0, 0, 0, 0, 0, 0 ]

scoresForneeds to return a list of 7 numbers for self

these are all of the opponent's evaluations of its next move…

[ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ] [ 0, 0, 0, 0, 0, 0, 0 ]

[50,50,50,50,50,50,50]

[50,50,50,50,50,100,50]

What score does the opponent give

each?

max(S) = 0

max(S) = 100

max(S) = 0max(S) = 0

max(S) = 0max(S) = 50

max(S) = 100

What score does self give each?

100

0100

100 10050

0

Page 76: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def scoresFor(self, b):(1) For each possible move

(2) Add it to the board b

(3) Ask OPPONENT its scoresFor each b at ply-1

(4) self's score is 100-max!

""" MUST return a list of 7 scores!! """

Page 77: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Difficulty == Branching Factor

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

• On average, there are fewer than 40 possible moves that a chess player can make from any board configuration… 0 Ply

1 Ply

2 Ply

Hydra at home in the United Arab Emirates…

Hydra looks ahead 18 ply !

Page 78: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

1 Ply

2 Ply

Boundaries for qualitatively

different games…

0 Ply

Page 79: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

“solved” games

computer-dominated

human-dominated

1 Ply

2 Ply

0 Ply

Progress

Page 80: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov
Page 81: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two-player games have been a key focus of AI as long as computers have been around…

Strategic thinking == intelligence?

… humans and computers have different relative strengths in these games.

humanscomputers

good at evaluating the strength of a board for a player

good at looking ahead in the game to find

winning combinations of moves

Page 82: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

How humans play games…

- experts could reconstruct these perfectly - novice players did far worse…

An experiment (by A. deGroot) was performed in which chess positions were shown to novice and expert players…

Page 83: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

How humans play games…

- experts could reconstruct these perfectly - novice players did far worse…

Random chess positions (not legal ones) were then shown to the two groups

- experts and novices did equally well (badly) at reconstructing them!

An experiment (by A. deGroot) was performed in which chess positions were shown to novice and expert players…

Page 84: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two-player games have been a key focus of AI as long as computers have been around…

Strategic thinking == intelligence?

humanscomputers

good at evaluating the strength of a board for a player

good at looking ahead in the game to find

winning combinations of moves

… humans and computers have different relative strengths in these games.

hw9 pr1

building an AI chess player

Page 85: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Player class

PlayerpForX

What data does an AI player need?

Let's see a demo!

stringox

stringtbt

'X' 'LEFT'intply

0

DATA MEMBERS

tiebreakTypechecker, O or X moves to look ahead

surprisingly little!

How about knowledge about its opponent?

Page 86: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Player

Board and Player methods

__init__(self, ox, tbt, ply)

__repr__(self)

scoreBoard(self, b)

scoresFor(self, b)

tiebreakMove(self, scores)

nextMove(self, b)

oppCh(self)

Board

__init__( self, width, height )

allowsMove( self, col )

__repr__( self )

addMove( self, col, ox )

isFull( self )

winsFor( self, ox )

hostGame( self )

delMove( self, col )

set_board( self, LoS )

Board's data also includes data!

All of Player's

data

Page 87: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoreBoard ‘X’‘O’

Assigns a score to any board, b

100.0 50.0 0.0A simple system:for a win for a lossfor anything else

Score for Score for

Score for Score for

Page 88: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoreBoard

Assigns a score to any board, b

100.0 50.0 0.0A simple system:for a win for a lossfor anything else

scoreBoard(self, b)

Implementation ideas…

What methods that already exist will come in handy?

This doesn't seem to be looking very

far ahead !

How can there be no 'X' or 'O' input?

What class is this method in?

Page 89: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead…

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are there to consider?

0-ply

1-ply

A 1-ply lookahead player will "see" an impending victory.

to move…

A score for each

column…?

scores

p42.scoresFor( b42 )

special case

Page 90: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead…

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are there to consider?

0-ply

A 2-ply lookahead player will also "see"

an opponent's impending victory.

to move…

What about 3-ply? 2-ply

1-ply score

scorep43.scoresFor( b42 ) and p44

Page 91: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead…

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are there to consider?

0-ply

1-ply

scoresFor( self, b ) returns a LIST of scores, one for each column you can choose to move next…

2-ply

Page 92: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

self

0-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

1-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

2-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

3-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

Score! ‘X’‘O’

Page 93: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

| | | | | | |O|| | | | | | |O|| | | | | | |X||X| |X|O| | |O||X|O|O|X| |X|X||X|O|O|O| |O|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

It is X’s move. What scores does a 2-ply lookahead for X assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

Which change at 3-ply?

Which change at 2-ply?

Example 1-ply and 2-ply lookahead scoreshttp://www.stanford.edu/~ccecka/research/C4.html

Page 94: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

| | | | | | |O|| | | | | | |O|| | | | | | |X||X| |X|O| | |O||X|O|O|X| |X|X||X|O|O|O| |O|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

It is X’s move. What scores does a 2-ply lookahead for X assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

be careful!

-1 100

50 100

50 100

50

100

0 0 0 50 0 -1

Which change at 2-ply? 0 0

Which change at 3-ply?0

Answers to example lookahead scoreshttp://www.stanford.edu/~ccecka/research/C4.html

Page 95: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

self

scoresFor each column

(1) For each possible move

(2) Add it to the board

Page 96: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT to score each board

At what ply?

0.0

50.0

50.0

0.00.0

50.0

0.0

scoresFor each column

self

Page 97: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT to score each board

(4) Which score will the opponent choose?

0.0

50.0

0.00.0

50.0

0.0

What, then, should assign for your score?

(self's score)

scoresFor each column

50.0

self

Page 98: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

500

1200

2000

2800

Computer Chess

early programs ~ 1960’s

Computers cut their teeth playing chess…

Ranking

beginner

amateur

world ranked

world champion

MacHack (1100) ~ 1967 MIT

Deep Thought ~ 1989 Carnegie Mellon

Slate (2070) ~ 1970’s Northwestern

Deep Blue ~ 1996 IBM

Deep Blue rematch ~ 1997 IBM

100’s of moves/sec

10,000’s of moves/sec

1,000,000’s moves/sec

3,500,000 moves/secDeep Fritz: 2002X3D Fritz: 2003 Hydra: 2006

200,000,000 moves/sec

first paper: 1950

What is Hydra's chess rating?

Page 99: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

• On average, there are fewer than 40 possible moves that a chess player can make from any board configuration… 0 Ply

1 Ply

2 Ply

Hydra at home in the United Arab Emirates…

Hydra looks ahead 18 ply !

Page 100: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

1 Ply

2 Ply

Boundaries for qualitatively

different games…

0 Ply

Page 101: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Games’ Branching Factors

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

“solved” games

computer-dominated

human-dominated

1 Ply

2 Ply

0 Ply

Progress

Page 102: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov
Page 103: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def scoresFor(self, b):(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT to score each board at ply-1

(4) self's score is 100-max

Page 104: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Write tiebreakMove to return the leftmost best score

inside the list scores

def tiebreakMove(self, scores):

if self.tbt == 'LEFT':

How would 'RANDOM' and 'RIGHT' work differently?

Page 105: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hwks and Projects

• Homework 9: A Connect Four Player…

• Homework 8: A Connect Four Board… due 11/19/09

due 12/23/09 !by the end of the term…

Page 106: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hwks and Projects

• Homework 9: A Connect Four Player…

• Homework 8: A Connect Four Board… due 11/19/09

due 12/23/09 !by the end of the term…

• Homework 8, part 2: final project proposal

Pre-planned projects Ideas Open-ended

4) robot navigation: pyRobot

2) 3d simulation game: vPool

1) Web-based Text Clouds

3) implementing Picobot!

Flash Cards ?

pySQL ?

Image processing

using pyGame: "snake"

others welcome!

Page 107: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Project Deliverables

• Proposal due 11/19/09

• Preliminary milestone due 12/3/09

one-page (proposal.txt) that includes your project choice and a first description of the project-specific ideas - also, what libraries you'll use

https://www.cs.hmc.edu/twiki/bin/view/CS5/ISProjectsPage

Working code (preliminary.zip) that uses your libraries and shows access to the data you need (sound, graphics, etc.) Also, a plan for the next steps to take -- this may include classes you'll build.

• Presentation / intermediate milestone due 12/9-10/09The presentation is ~10 minutes of your vision, the technical details, and a demo of what you have so far. The intermediate.zip milestone should have the presentation, demo, and a final plan, including classes.

• Project due 12/17/09Your final project (project.zip), with documentation and "future work."

Page 108: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Examples?!

Date, due Date(11,11,09).tomorrow()

Page 109: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

Which change at 2-ply?

Page 110: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead …

0 ply:

2 ply: 3 ply:

Zen choice of move: here and now

| | | | | | | || | | | | | | ||O| | | | | | ||X| | | | | | ||X|O|O| | |X| ||O|X|X|O|X|O| |--------------- 0 1 2 3 4 5 6

| | | | | | | || | | | | | | || | | | |X| | || | | | |O|O| || |X|X| |X|O| ||O|X|O| |O|X| |--------------- 0 1 2 3 4 5 6

(1) Player will win

(2) Player will avoid losing

(3) Player will set up a win by forcing the

opponent to avoid losing

X’s move X‘s move

1 ply:

| | | | | | | || | | | | | | || | | | | | | || | | | | | | || |O|X| | | | ||O|X|X|X| |O|O|--------------- 0 1 2 3 4 5 6

X’s move

Page 111: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b

Choosing the best move

(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT to score each board - ply?

(4) Reverse the scores

100.0

50.0

50.0

100.0100.0

50.0

100.0

Page 112: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

‘X’‘O’new‘X’

Col 6

Col 5

Col 4Col 3Col 2

Col 1

Col 0

b

Choosing the best move

100.0

50.0

50.0

100.0100.0

50.0

100.0

(1) For each possible move

(2) Add it to the board

(3) Ask OPPONENT to score each board - ply?

(4) Reverse the scores

(5) Find one max - that's it!

Page 113: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 6

Suppose our Board class's 2d list of lists is named self.data. What is

the name of this single spot?

For your convenience, the creators of Python’s library have included a Board class that can represent any size of Connect Four board... !

Page 114: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

This is true for sufficiently broad definitions of “the creators of Python’s library” ...

Boardb

def addMove(self, col, player)

intNROWS

intNCOLS

def allowsMove(self, col)

char char char

char char char

char char char

datalist char

char

char

def winsFor(self, player)

data members

methods

What is player ?

Page 115: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

This is true for sufficiently broad definitions of “the creators of Python’s library” ...

Boardb

def addMove(self, col, player)

intNROWS

intNCOLS

def allowsMove(self, col)

char char char

char char char

char char char

datalist char

char

char

def winsFor(self, player)

data members

methods

Which methods will alter b? Which leave it alone?

Page 116: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: Board

Starting code for the Board class

class Board: def __init__( self, numRows, numCols ): """ our Board's constructor """ self.NROWS = numRows self.NCOLS = numCols self.data = [] for r in range(self.NROWS): onerow = [' ']*self.NCOLS self.data += [onerow]

def __repr__(self): """ thoughts? """

look familiar?

Page 117: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: Boardclass Board: def __init__( self, numRows, numCols ): """ our Board's constructor """ self.NROWS = numRows self.NCOLS = numCols self.data = [] for r in range(self.NR): onerow = [' ']*self.NC self.data += [onerow]

def __repr__(self): """ thoughts? """ s = '\n' for r in range(self.NROWS): s += '|' for c in range(self.NCOLS): s += self.data[r][c] + '|'

return s

look familiar?

a bit more to go !

Page 118: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Problem 2

class Board

__init__

allowsMove

__repr__

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw11 Pr2: Connect Four Board

hostGame play!

What's trickiest here?

Page 119: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Problem 2

class Board

__init__

allowsMove

__repr__

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw11 Pr2: Connect Four Board

hostGame play!

What's trickiest here?

Page 120: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

What's wrong here?

| | | | | | | || | | | | | | || | | | | | | || | | |O|O| | ||X|X| |O|X|X|X||X|O|O|O|O|X|X|--------------- 0 1 2 3 4 5 6

def winsForHoriz(self, player): inarow = 0

for r in range(self.NROWS): for c in range(self.NCOLS):

if self.data[r][c] == player: inarow += 1 else: inarow = 0

if inarow == 4: return True

return False

Page 121: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Strategies?

horizontals

verticals

diagonals ??| | | | | | | || | | | | | | || | | | | | | || | | |O|O| | ||X|X| |O|X|X|X||X|O|O|O|O|X|X|--------------- 0 1 2 3 4 5 6

Page 122: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

“Quiz”class Board{ # __init__ and __repr__ methods here… # 3 data members: # self.NR == number of rows # self.NC == number of cols # self.data == the 2d list of lists of chars

def mysteryMethod(self, col, ox): r = 0 while r < self.NR and self.data[r][col] == ' ': r += 1 self.data[r-1][col] = ox

def allowsMove(self, col):

}

Briefly, what is each line of the mysteryMethod doing?

Which method is it?

Write allowsMove to return whether the input col is a valid column to move.

(True or False)

1

2

3

Could it go wrong?

Page 123: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Problem 2

class Board

__init__

allowsMove

__repr__

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw11 Pr2: Connect Four Board

hostGame play!

What's trickiest here?

Page 124: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Problem 2

class Board

__init__

allowsMove

__repr__

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw11 Pr2: Connect Four Board

hostGame play!

What's trickiest here?

Page 125: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Strategies?

horizontals

verticals

diagonals ??| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|O| |O|--------------- 0 1 2 3 4 5 6

Page 126: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

|O| | | | | | ||X| | | |O| |X||O| | | |X|O|X||X| | | |O|O|X||X| |X| |X|O|O||X| |O|O|O|X|X|--------------- 0 1 2 3 4 5 6

It is O’s move. What scores does a 1-ply lookahead for O assign to each move?

col 0 col 1 col 2 col 3 col 4 col 5 col 6

Which change at 2-ply?

Example 1-ply and 2-ply lookahead scores

Page 127: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

0-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

1-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

2-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

3-ply scores for O:col 0 col 1 col 2 col 3 col 4 col 5 col 6

Solutions

-1

-1

-1

-1

50 50 50 50 50 50

50 50 100

50 50 50

0

0

100

100

0

0

0 0 50

100

00

b ‘X’‘O’

Page 128: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

IS313 …

Monday, Nov. 8 - Classes + Objects, part 2

Monday, Nov. 15 - Project strategies & example pres.

Tuesday, Nov. 9 - Date class due

Tuesday, Nov. 16 - Board class due & proj. idea

Monday, Nov. 22 - UIs & another example presentation

Wed., Dec. 1 - preliminary report due – with code

Monday, Dec. 6 - In-class project presentations

Tuesday, Dec. 7 - intermediate report – with code

Monday, Dec. 13 - no class meeting, but I'll be available...

Thursday, Dec. 17 - Final project due!

Final HW

IS 313 Schedule

Final Project

Tuesday, Nov. 23 - no HW due

Monday, Nov. 29 - no class meeting (conference)

Page 129: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

AI: Artificial Intelligence

Monday, Nov. 8 - Classes + Objects, part 2

Monday, Nov. 15 - Project strategies & example pres.

Tuesday, Nov. 9 - Date class due

Tuesday, Nov. 16 - Board class due & proj. idea

"High-level AI"

Game-playingNatural Language

TranslationTask planning

"Low-level AI"

RoboticsSensing and reacting

Computer visionAdapting to human actions

Page 130: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

IS313: software intelligence

An object is structured data that is alive, responsible, and intelligent.

Sound too friendly?

This week’s objects and classes will be just the opposite ...

X to move.

Is there a way to win?

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X|O| |--------------- 0 1 2 3 4 5 6

import antigravity!

Page 131: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Designing classes

1) What data? (Data Members)

2) What are the key capabilities? (Methods)

Not limited to 7x6!

Page 132: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

BoardB

intwidthstr str str

str str str

str str str

datalist str

str

str? int

height

What is the name of the method that will construct this data?

Starting from B, how would you examine the string marked by the ?

3

4

Page 133: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: constructor

class Board: """ a datatype representing a C4 board with an arbitrary number of rows and cols """ def __init__( self, width, height ): """ the constructor for objects of type Board """ self.width = width self.height = height self.data = [] # this will be the board for row in range( self.width ): boardRow = [] for col in range( self.height ): boardRow += [' '] # add a space to this row self.data += [boardRow]

Better! Same idea as in Life

Page 134: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: constructor

class Board: """ a datatype representing a C4 board with an arbitrary number of rows and cols """ def __init__( self, width, height ): """ the constructor for objects of type Board """ self.width = width self.height = height self.data = [] # this will be the board self.data = [ [' ']*self.width for row in range(self.height) ]

Even shorter!

What was this called again… ?

Page 135: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Connect Four: the object b

Boardb

intwidth

str str str

str str str

str str str

datalist

str

str

str

intheight

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 6

67

X O O O

X X

X

……

printed version

Which rows and columns are these?

which is row 0 ?

Page 136: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def __repr__(self): """ this method returns a string representation for an object of type Board """ s = '' for row in range( self.height ): s += '|' for col in range( self.width ): s += self.data[row][col] + '|' s += '\n'

return s

Connect Four: __repr__

What else?

Page 137: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

>>> b = Board( 7, 6 )

>>> print b

>>> LoS = [ ' ', ' ', 'OXO ', 'XXOO ', 'XOXXOX ', 'XOOXXOO' ]

>>> b.set_board( LoS )

>>> print b

Connect Four: set_board

| | | | | | | || | | | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

| | | | | | | || | | | | | | || | | | | | | || | | | | | | || | | | | | | || | | | | | | |--------------- 0 1 2 3 4 5 6

What is this a list of?

Page 138: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

def set_board(self, LoS): """ this method sets the board to the list_of_strings that is input """ for row in range( ):

for col in range( ):

self.data[row][col] = LoS[row][col]

Connect Four: set_board

What goes in the blanks?

Page 139: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Try it!

def addMove(self, col, ox):

row = self.height-1 while True: if self.data[row][col] == ' ': self.data[row][col] = ox

row -= 1

Step through this addMove method.

How does it work?

What's wrong?

Try to fix it… !

a C4 board

col #'O' or 'X'

| | | | | | | || | | | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

Page 140: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Try it!def allowsMove(self, col):

a C4 board col #

allowsMove should return True if col has enough space

to allow a move; it should return False otherwise.

| |X| | | | | || |O| | | | | ||O|X|O| | | | ||X|X|O|O| | | ||X|O|X|X|O|X| ||X|O|O|X|X|O|O|--------------- 0 1 2 3 4 5 6

b

b.allowsMove(0)

b.allowsMove(1)

True

False

Page 141: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

C4 Board class: methods

__init__( self, width, height )

allowsMove( self, col )

__repr__( self )

addMove( self, col, ox )

isFull( self )

winsFor( self, ox )

the “constructor”

checks if allowed

places a checker

outputs a string

checks if any space is left

checks if a player has won

hostGame( self )play!

delMove( self, col )removes a checker

What will require the most thought?

set_board( self, LoS )sets the board arbitrarily

Page 142: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Checking wins… ?

Thoughts?

X O

self

corner cases?

Page 143: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Two-player games have been a key focus of AI as long as computers have been around…

Strategic thinking == intelligence?

In 1945, Alan Turing predicted that computers

would be better chess players than people in

~ 50 years…

and thus would have achieved intelligence.

Alan Turing memorial Manchester, England

Page 144: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

500

1200

2000

2800

Computer Chess

early programs ~ 1960’s

Computers cut their teeth playing chess…

Ranking

beginner

amateur

world ranked

world champion

MacHack (1100) ~ 1967 MIT

Deep Thought ~ 1989 Carnegie Mellon

Slate (2070) ~ 1970’s Northwestern

Deep Blue ~ 1996 IBM

Deep Blue rematch ~ 1997 IBM

100’s of moves/sec

10,000’s of moves/sec

1,000,000’s moves/sec

3,500,000 moves/secDeep Fritz: 2002X3D Fritz: 2003 Hydra: 2006

200,000,000 moves/sec

first paper: 1950

What is Hydra's chess rating?

Page 145: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

How humans play games…

- experts could reconstruct these perfectly - novice players did far worse…

Random chess positions (not legal ones) were then shown to the two groups

- experts and novices did equally well (badly) at reconstructing them!

An experiment (by A. deGroot) was performed in which chess positions were shown to novice and expert players…

Page 146: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

scoreBoard(self,b) ‘X’‘O’

Assigns a score to any board, b

100.0 50.0 0.0A simple system:for a win for a lossfor anything else

Score for Score for

Score for Score for

Page 147: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Looking further ahead…

scoreBoard looks ahead 0 movesThe "Zen" approach --

we are excellent at this!

If you look one move ahead, how many possibilities are

there to consider?

0-ply

1-ply

A 1-ply lookahead player will "see" an impending victory.

turn

A score for each

column…?

scores

p42.scoresFor( b42 )

special case

Page 148: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Difficulty == Branching Factor

Branching Factor Estimatesfor different two-player games

Tic-tac-toe 4

Connect Four 7

Checkers 10

Othello 30

Chess 40

Go 300

• On average, there are fewer than 40 possible moves that a chess player can make from any board configuration… 0 Ply

1 Ply

2 Ply

Hydra at home in the United Arab Emirates…

Hydra looks ahead 18 ply !

Page 149: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hwks and Projects

• Homework 8, part 0: final project proposal

Pre-planned projects Ideas Open-ended

4) robot navigation: pyRobot

2) 3d simulation game: vPool

1) Web-based Text Clouds

3) implementing Picobot!

Flash Cards ?

pySQL ?

Image processing

using pyGame: "snake"

others welcome!

• Extra: A Connect Four Player…

• Homework 8: A Connect Four Board… due 11/16/10

ok anytimewell, by the end of the term…

Low-level computation?

Page 150: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Project Deliverables

• Proposal due 11/16/10

• Preliminary milestone due 12/1/10

one-page (proposal.txt) that includes your project choice and a first description of the project-specific ideas - also, what libraries you'll use

https://www.cs.hmc.edu/twiki/bin/view/CS5/ISProjectsPage

Working code (preliminary.zip) that uses your libraries and shows access to the data you need (sound, graphics, etc.) Also, a plan for the next steps to take – initial functions and/or classes you plan to build.

• Presentation / intermediate milestone due 12/6 & 12/7The presentation is ~10 minutes of your vision, the technical details, and a demo of what you have so far. The intermediate.zip milestone should have the presentation, demo, and a final plan, including classes.

• Project due 12/17/10Your final project (project.zip), with documentation and "future work."

Page 151: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Hey! Watch where you're going!

The pyRobot project

Goal: get from Pt A to Pt B2d Roomba simulator

How do I control this robot !?!

Pt B

Pt A

Page 152: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The pyRobot project

Robot control continuously runs three things:

SENSE PLAN ACT

[x,y,thd], bump = self.getData()

if bump[0] == True or bump[1] == True: print 'BUMP!', print ' [Left bump sensor:', bump[0], '] ', print ' [Right bump sensor:', bump[1], '] ' robotTask = STOP

STOP is one of the robot's states. Every 40th of a second, the robot runs through this loop, sets the robot's state and sets the velocities accordingly. Don't sleep!

if robotTask == STOP: self.setVels(0,0) robotTask = KBD

while True:

Page 153: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

PicoRoomba!

The pyRobot project ~ additions

Goal: get from Pt A to Pt B

Start in an unknown location on the map…

vPython Roomba?

ASCII Roomba?Use only the bump sensors… (no range sensing)

Implement a niftier interface…

Try it out on a Roomba…

Use noisy (realistic) data

Optional

Main

Page 154: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Let’s play!

I’ll take your cue.

3d simulator, VPython

The vPool project

Page 155: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The vPool project

from visual import *

floor = box( pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)

ball = sphere( pos=(0,4,0), radius=1, color=color.red)

ball.velocity = vector(0,-1,0)dt = 0.01

while True: rate(100) ball.pos = ball.pos + ball.velocity*dt

if ball.y < ball.radius: ball.velocity.y = -ball.velocity.y else: ball.velocity.y = ball.velocity.y - 9.8*dt

How many classes?

How many objects?

data members?

What's the if/else

doing?

Page 156: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

• Text and graphical output• Read Picobot program from a file• Read maze description from a file• Track visited/unvisited squares• Prohibit illegal moves• Stop when maze completely visited

The Picobot project

Required capabilities:

Page 157: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

The Picobot project

• Choice of graphical packages • vpython• turtle• csplot/csgrid (Game-of-Life)

• Start/stop/step feature• Maze editing• Pebble dropping• Be inventive!

csplot or csgrid version…Graphical picobot:

Lots of options…

Page 158: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

tag cloud'07

?

Page 159: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

From text…

… to cloud

1. Start with entered webpage (URL)

2. Read in text

3. Create list of words out of text

4. "Clean" the words

5. "Stem" the words

6. Count the words

7. Return a string with frequencies

8. Add advanced features…

Huh?

Page 160: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

http://www.cs.hmc.edu/~cs5grad/cs5/textcloud/page1.html

Spamming spammers spammed spam. Spam spam spam! I love spam!

['spamming', 'spammers', spammed', 'spam', 'spam', 'spam', 'spam','love', 'spam', 'page', '2']

['spamming', 'spammers', spammed', 'spam.', 'spam', 'spam', 'spam!','I', 'love', 'spam!', 'page', '2']

['spam', 'spam', spam', 'spam', 'spam', 'spam', 'spam','love', 'spam', 'page', '2']

Page 2

What changed here?

What next?

Page 161: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Text Clouds project

Suggested Approach: Develop the basic application the usual way, using IDLE.

• Once you have everything working,

transfer your files to your webspace.

set up the HTML wrapper files & go…

Hypertext Markup Language

• Use the provided code to read HTML

• Personalize - There are lots of ways to do this!

• Once you have things working, move on to writing HTMLfollowing links beyond depth 1avoiding repeated links!

• Make sure that you can process the files appropriately into ordered lists of words…

Page 162: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Other ideas...

Low-level computation ~ circuits ?

Javascript? ~ flash cards ? maps ?

Images? ~ online salon ? illusions ?

Page 163: IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov. 15 - Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov

Let me know!

Hw8 part 1: A Connect Four Board

Hw8 part 0: project idea and proposal