The CS 5 Herald Goodwill Gesture Goes Awry Claremont (AP) : Seven rooms were damaged in a Harvey Mudd College dormitory Tuesday evening after a misguided.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Knowledge Representation
Advertisements

Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Heuristic Search techniques
Python Objects and Classes
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Classes 2 COMPSCI 105 SS 2015 Principles of Computer Science.
Rapid GUI Programming with Python and Qt Classes and Modules By Raed S. Rasheed Classes and Modules By Raed S. Rasheed 1.
AI for Connect-4 (or other 2-player games) Minds and Machines.
Artificial Intelligence in Game Design
HW 6: Problems 2&3 Simulating Connect 4.
Mahgul Gulzai Moomal Umer Rabail Hafeez
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
CPSC 322 Introduction to Artificial Intelligence November 10, 2004.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
A TIE IS NOT A LOSS Paul Adamiak T02 Aruna Meiyeppen T01.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Othello.
CS 280 Data Structures Professor John Peterson. Lexer Project Questions? Must be in by Friday – solutions will be posted after class The next project.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
Floating point numbers in Python Floats in Python are platform dependent, but usually equivalent to an IEEE bit C “double” However, because the significand.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
Classes 3 COMPSCI 105 S Principles of Computer Science.
CISC 235: Topic 6 Game Trees.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Computing Science 1P Large Group Tutorial 17 Simon Gay Department of Computing Science University of Glasgow 2006/07.
CIT 590 Intro to Programming Style Classes. Remember to finish up findAllCISCourses.py.
Python Programming Chapter 14: Classes and Methods Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Game Playing.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
XSLT + Xpath CS High level view We are doing tree editing Changes to node properties Structural rearrangement Several mdels for this kind of task.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
Def tomorrow(self): """Changes the calling object so that it represents one calendar day after the date it originally represented. """ if self.month in.
Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.
CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Game Playing. Towards Intelligence? Many researchers attacked “intelligent behavior” by looking to strategy games involving deep thought. Many researchers.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
W 2 L 1 sh 1 C lessons LessonSubjectBook Week 1 lesson 1Objects, names Week 1 lesson 2Statements, layout Week 2 lesson 1Functions, decomposition Week 2.
Introduction to OOP OOP = Object-Oriented Programming OOP is very simple in python but also powerful What is an object? data structure, and functions (methods)
1 Programming for Engineers in Python Autumn Lecture 6: More Object Oriented Programming.
CPS Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze  Certain mazes can be solved using the “right-hand”
Today’s Topics Playing Deterministic (no Dice, etc) Games –Mini-max –  -  pruning –ML and games? 1997: Computer Chess Player (IBM’s Deep Blue) Beat Human.
Operator Overloading Week 5.
CompSci 100e 6.1 Plan for the week l More recursion examples l Backtracking  Exhaustive incremental search  When we a potential solution is invalid,
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
CompSci Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze ä Certain mazes can be solved using the.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Q and A for Sections 6.2, 6.3 Victor Norman CS106.
CPS Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze ä Certain mazes can be solved using the “right-hand”
CompSci Recursion & Minimax Recursion & the Minimax Algorithm Key to Acing Computer Science If you understand everything, ace your computer science.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
CPS 100, Spring Search, Backtracking,Heuristics l How do you find a needle in a haystack?  How does a computer play chess?  Why would you write.
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
Search: Games & Adversarial Search Artificial Intelligence CMSC January 28, 2003.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
The CS 5 Sun Crushing Athletic Defeat
EECS 110: Lec 15: Classes and Objects (2)
COMPSCI 107 Computer Science Fundamentals
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
The CS 5 Black Post Penguins Invade Dormitory
Topic 1: Problem Solving
Recursion Taken from notes by Dr. Neil Moore
EECS 110: Lec 15: Classes and Objects (2)
Backtracking, Search, Heuristics
Presentation transcript:

The CS 5 Herald Goodwill Gesture Goes Awry Claremont (AP) : Seven rooms were damaged in a Harvey Mudd College dormitory Tuesday evening after a misguided attempt to cheer up sleep-deprived students. “We were approached by a group of three penguins who wanted to sing Christmas carols,” explained a witness. “They promised that it would help us study.” Instead, the raucous squawking of the untrained and untalented birds quickly led to a violent dispute between supporters and detractors. One student attempted to encase the singers in foam rubber, but a second set fire to the material in hopes of freeing the animals. The resulting explosion unleashed a conflagration that spread to North Dorm, where there was extensive damage. However, losses in North were estimated at only $35.47, due to the advanced age of the furniture there.

“Forced” Methods Some methods are required by language Must always have __init__ Good to have one of __repr__ or __str__ Others not required, but very common copy (to do deep copies) show (to print self)

Construction and Destruction Constructor ( __init__ ) builds an instance Called when object created Best to initialize everything to reasonable values Destructor ( __del__ ) rarely needed Unlike C++ Unpredictable when (or if) it's called Best to avoid

__repr__ and __str__ __str__ implements the str (…) built-in Automatically called by print __repr__ should give Python syntax E.g., Date(11, 26, 2007) Automatically called when interpreter is returning a result If __str__ undefined, __repr__ used Quick shortcut: only do the latter

Class Globals ("statics") How to put debug in your Date class? Don't want to depend on user's debug Might not exist User might not care about Date debugging Solution: variable that's global within class Only one copy across all objects Also useful for things like counting objects

A Self-Counting Class class Counter: instances = 0 def __init__(self): self.id = Counter.instances Counter.instances += 1 def unique(self): return self.id

Computational Classes It’s often useful to define classes that provide mathematical objects Infinite-precision numbers Rational numbers Matrices Modular fields Writing code using these classes can be painful: y = add(mult(a,mult(x,x)),add(mult(b,x),c))

Operator Overloading Overloading means giving an operator (or function) a definition that depends on context Example: a/b means something different depending on whether a and b are int s or float s Some languages (including Python) let users overload operators at will y = a*x*x + b*x + c

Overloading in Python Most Python operators can be overloaded Just define a special function in a class Annoying exception: plain assignment Many finicky rules Names aren’t always obvious Some operators have “forward” and “reverse” versions Some operators derive from others by default

Basic Overloading class MyMath: def __init__(self, …): … def __add__(self, rhs): # Only works if rhs is a MyMath result = self.value + rhs.value return result def __sub__(self, rhs): … # etc.

Important Details Overloaded operators should return a result Should not modify “self” or right-hand side Often useful to have copy method Exception: Ops in “i” series modify “self” Possibility of rhs not being same type Many packages don’t handle this case well

Overloaded Operator Naming + add - sub * mul / div / truediv (future) // floordiv % mod ** pow + pos - neg abs int float complex == eq != ne <= le >= ge < lt > gt Remember, every name needs two underscores before and after it!

The r… and i… series radd, rsub, etc. implement reversed operators If x is special and y is built-in (e.g., integer), then x+y invokes x.add(y), and y+x invokes y.radd(x) However, if radd isn’t defined, Python will try y.add(x) iadd, isub, etc. implement incremental operators E.g., x.iadd(y) implements x += y Modifies x Should return None (i.e., no explicit return value)

The Alien’s Life Advice Ask questions when you don’t get it! It makes you seem human! OK, maybe you won’t get a date with Xohptzl, but you’ll learn more!

Worksheet: Designing a Class Design class Rational, to store rational numbers (integer divided by integer) Choose reasonable string representation Enumerate data, "special" functions, things it should be able to do E.g., a.add(b) adds b to a, modifying a I looove rationals! They’re so logical!

More On Rationals Should there be any “extra” methods beyond the obvious mathematical ones?

Rules for Connect Four Tic-Tac-Toe with stacking 7x6 board Checkers slide down onto top of column Four in a row (including diagonal) wins

A C4Board Class class C4Board: width = 7 height = 6 def __init__(self): board = [width*[0] for i in range(height)] …

Artificial Intelligence Catch-all term for anything that “appears human” Eliza Chess programs Expert systems Many approaches N-ply lookahead: good for games

Looking into the Future, Part I Basic idea Guess a move See whether it makes your position better Repeat for many guesses, pick best result What defines “better”? Simple answer: use board evaluation function

Evaluating a Connect-4 Board What are some ways to numerically rate a Connect-4 board? If opponent has won, 0.0 If I have won, 1.0 Otherwise… ?

Looking Into the Future, Part II Problem: evaluating a board is HARD Solution: look at where the board leads For each possible move: Make the move in “trial mode” For each possible opponent's response: Make that move in “trial mode” Evaluate that board instead (how?) Return value of opponent's best option This is the “worst case” for us Our best move is “best of the worst cases”

Limiting Recursion When do we stop? That's easy: When we find path that leads to a win No matter what opponent does (e.g., Nim) When all paths lead to losses (sigh) When we have explored all possible moves

The Move Tree X O X O X O X O X X O X O X O X O X O X X O X X O X O X X O X X O X X O X X

Explosive Growth Connect-4 move tree has < 7 42 nodes Roughly 311×10 33 Tree size depends on two parameters: Branching factor per move, B Maximum moves in game, N Approximately B N possibilities Chess: B≈35, N≈150 Backgammon: B≈300, N≈50

Limiting Growth Simplest strategy: stop looking ahead after evaluating N moves (“plies”) Alternative: stop after t seconds elapsed Better: prune move tree Don't follow a path if first move is way worse Don't explore if already found better choice Alpha/Beta pruning

The Curse of the AI Researcher AI is always defined as “something a lot smarter than what my computer can do” Corollary: if my computer can do it, it's not artificial intelligence ⇒ Every time we achieve AI, people decide it's not really AI!