CS 5 Today: two I's AI UI hw11pr2.p y an arbitrarily- good Connect 4 player! Player class Extra: scoreBoard4Tourney an intuitive Connect 4 player: hw11pr1.htm l I wish there were three i's! Hw 11 is due Tuesday, 11/24 M/T 11/23-24 Introduction to final projects After Thanksgiving TheoComp! T 11/24 10pm Ex.Cr. circuits lab… W 11/25 1:15pm Ex.Cr. circuits lab… Schedule:
96
Embed
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.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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
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
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!
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?
hw11 this week
• Extra: scoreBoard4Tourney and a CS 5 C4 round-robin
http://www.stanford.edu/~ccecka/research/C4.html
Using more scores than 0, 50, and 100 !
• Problem 2: A Connect Four Player…
don't give this board a 50.0 !
• Problem 1: (Lab) Trying out a command-line user interface
User Inferfaces
No undo!
% ls
file1.txt file2.txt
file3.txt !
% rm *!
(long pause…)
Design for software and beyond
0. Conceptual
models
1. Mapping
2. Visibility
3. Feedback
4. Affordances
Don Norman's key principles:
Conceptual Models
Users always bring something "to the table"
these don't work!
Images from The Design of Everyday Things
Mapping
is matching expected (spatial) relationships
Where to plug in the keyboard and mouse?
?
Visibility
is making functionality apparent
Shower?Slide projector…
From: www.baddesigns.com
"I used to have that awful shower controller where you pull down on the nozzle to turn it on. I had to tell every guest how to do it, and when we sold our house, we got a call from the new owners about 5 days later asking how to turn on the shower. They had been taking baths for 5 days! Unbelievable." - BL
Feedback
providing information back to the user
from the UI Hall of Shame
Microsoft Access
Microsoft Outlook
http://homepage.mac.com/bradster/iarchitect/shame.htmBut some of us graphics aren't so lazy!
Affordances
are the functions that form suggests…
Opening the XO? Door handles
built-in user's manual
Where do these go wrong?Mapping
How to open this gas cap?
Visibility Feedback Affordances
This handle unfastens the seat from the
floor.
How to turn on this stove?
Set to 5 minutes?
Win NT Dialog
The designers aren't the users…
See you on Monday!
Remember: CS Hw #11 is due next Tuesday…
Thinking about User Interfaces
Command Line Tablet / Touch
Ambient Information
Display Walls
Thinking about User Interfaces
What other types of human/computer interfaces can you think of?
#1 WI
MP
indowsconsenusointer
GUI
Affordances~ physical and cultural expectations
0. Conceptual models 1. Mapping
Matching user expectations e.g., Directory structures
Visibility and Feedback
Banks of glass doorsSlide projector
Affordances The functions that form suggests! Phone settings
Affordances: to give a clue• Affordances: The perceived and actual properties of an object that signal of the object can be used (from The Design of Everyday Things)
Physical Affordances
Physical Affordances
What do the Zune wheel and the door handle have in common?
Virtual AffordancesClick Me Click Me
"Quiz"
Name(s):
Note the perceivedaffordances inthis interface.Are there anythat are missing?Misleading?
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.
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
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’
Connect Four: the object b
Boardb
intwidthstr str str
str str str
str str str
datalist str
str
str
data
intheight
What is the name of the method that will construct this data?
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( 6 ): boardRow = [] for col in range( 7 ): boardRow += [' '] # add a space to this row self.data += [boardRow]
What is the name of the method that will print this data?
def __repr__(self): """ this method returns a string representation for an object of type Board """ s = '' for row in range( 6 ): s += '|' for col in range( 7 ): s += self.data[row][col] + '|' s += '\n'
return s
Connect Four: __repr__
To remove?
To add?
which row is row 0, row 1, and so on?
Examples
def addMove(self, col, ox):
row = self.height-1 while True: if self.data[row][col] == ' ': self.data[row][col] = ox
row -= 1
def allowsMove(self, col):
Step through this addMove method.
How does it work?
What's wrong?
a C4 board
col #'X' or 'O'
allowsMove should return True if col is a valid move;
False otherwise.
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
Which is trickiest… ?
Checking wins… ?
Thought
s?
X O
b
corner cases?
A whole new class of programming
CS 5 today
Mon., 11/26Wed., 11/28
Mon., 12/3
Software Engineering
Final projects
TheoComp !
Exam review
Python's Date class
Wed., 12/5Mon., 12/10
Lab and HW #11
Hey! How did you get a
body?
Choose your side…
Exam 2
Exam 2
Problem 1b Problem 2
def zerospan( L, hi, low ):
for i in range(len(L)):
if low <= L[i] <= hi:
L[i] = 0.0
def zerospan( L, hi, low ):
for x in L:
if low <= x <= hi:
x = 0.0
def ROOKnotcastle( B, r, c ):
for row in range(len(B)):
for col in range(len(B[0])):
if row == r or col == c:
B[row][col] = 1
This does not change L!
def zerospan( L, hi, low ):
for x in L:
if low <= x <= hi:
x = 0.0
CAUTION: This does not change L!
Sets values between low and hi to 0.0.
Exam 2Problem 3
00 read r1 # input to r1
01 add r2 r2 r1 # add into r2
02 jnez r1 00 # if r1 != 0: goto 00
03 write r2 # else: write the sum
using the stack -- Aargh!adding in place :-)
Exam 2Problem 5
ruler( 1 )
ruler( 2 )
'1'
'212'
ruler( 3 ) '3231323'
ruler( 4 ) '434243414342434'
s si
def ruler( n ):
s = ''
for i in range(n,0,-1):
s += str(i) + s
return s
Exam 2
Exam 2
A whole new class of programming
CS 5 today
Mon., 11/26Wed., 11/28
Mon., 12/3
Software Engineering
Final projects
TheoComp !
Exam review
Python's Date class
Wed., 12/5Mon., 12/10
Lab and HW #11
Hey! How did you get a
body?
Choose your side…
Exam 2
Exam 2
Exam 2
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