This week's classes Connect 4 Player

Slides:



Advertisements
Similar presentations
EECS 110: Lec 14: Classes and Objects Aleksandar Kuzmanovic Northwestern University
Advertisements

Lists Introduction to Computing Science and Programming I.
An Introduction to Python – Part IV Dr. Nancy Warter-Perez.
SVSM 2008 Mathematical Modeling.  Easy to learn  3D Interactive modeling  Python – background language  Main site
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
GameMaker.  A lot of Different Definitions  Easier to Say What is NOT a Game  Movie is Not a Game  No Active Participation  Final Outcome is Fixed.
Recitation 1 Programming for Engineers in Python.
Programming 101 with Python: an open-source, cross-platform, and fun language By J. Burton Browning, Ed.D. Copyright © J. Burton Browning All rights reserved.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Introduction to TouchDevelop
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Make a blank window This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In script mode create a file.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Programming Video Games
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
EECS 110 Projects 1&2 Juan Li – Project 1 Ning Xia – Project 2.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Creating visual interfaces in python
Python Let’s get started!.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Into 3D with VPython Deepak Mishra MS-IT IIIT Hyderabad.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
Shawn Weatherford Saint Leo University
Katherine Kampf / kkampf
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Whatcha doin'? Aims: To start using Python. To understand loops.
Catapult Python Programming Session 4
CSCI 203: Introduction to Computer Science I
I/O Streams File I/O 2-D array review
WITH PYGAME ON THE RASPBERRY PI
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python – May 18 Quiz Relatives of the list: Tuple Dictionary Set
Python Let’s get started!.
Human Computer Interaction
Week 12 - Thursday CS 113.
Tuples and Lists.
Goals Give student some idea what this class is about
Topic: Functions – Part 2
CSC 108H: Introduction to Computer Programming
Functions CIS 40 – Introduction to Programming in Python
Let's Race! Typing on the Home Row
This week's classes Connect 4 aiMove
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Introduction to javadoc
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Introduction to Python
Interfaces and Constructors
Guide to Programming with Python
CS190/295 Programming in Python for Life Sciences: Lecture 6
I210 review.
Introduction to TouchDevelop
EECS 110: Lec 4: Functions and Recursion
This week's classes Connect 4 aiMove
Lists Part 1 Taken from notes by Dr. Neil Moore
Rocky K. C. Chang 15 November 2018 (Based on Dierbach)
Week 6: Time and triggers!
Using Lists and Functions to Create Dialogue
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to javadoc
Northwestern University
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Selection Statements Chapter 3.
CSCI 203: Introduction to Computer Science I
Class code for pythonroom.com cchsp2cs
Python Reserved Words Poster
Presentation transcript:

This week's classes Connect 4 Player Homework #11, due 11/21 Notice that the value of (dimension + eyes) is conserved! Three-eyed? This week, we're 3d'ed! Connect 4 Player

Python objects + classes... used by VPython Tuples are similar to lists, but they're parenthesized: T = (4,2) V = (1,0,0) example of a two-element tuple named T and a three-element tuple named V

Tuples! Lists that use parentheses are called tuples: but what about that name?! Lists that use parentheses are called tuples: >>> T = ( 4, 2 ) >>> T (4, 2) >>> T[0] 4 >>> T[0] = 42 Error! >>> T = ('a',2,'z') >>> Tuples are immutable lists: you can't change their elements... ...but you can always redefine the whole variable, if you want! + Tuples are more memory + time efficient + Tuples can be dictionary keys: lists can't

Creating 0- and 1-tuples would seem like a problem! Tuple problems… Creating 0- and 1-tuples would seem like a problem! A bug from yesterday's Board class: W = 4 # for example s = ' ', for col in range(W): s += str(col), ' ' without the first comma, it's an error yields a surprising result for s:

Creating 0- and 1-tuples would seem like a problem! Tuple problems… Creating 0- and 1-tuples would seem like a problem! A bug from yesterday's Board class: W = 4 # for example s = ' ', for col in range(W): s += str(col), ' ' without the first comma, it's an error yields a surprising result for s: (' ', '0', ' ', '1', ' ', '2', ' ', '3', ' ') starting value

Python details... (used, by, VPython) Functions can have default input values and can take named inputs def f(x=3, y=17): return 10*x + y example of default input values for x and y f(x=4,y=2) example of named input values for x and y Function inputs look like tuples, but they're not exactly the same…

Python details in VPython… Functions can have default input values and can take named inputs def f(x=3, y=17): return 10*x + y example of an ordinary function call – totally OK f(4,2) example of two default inputs f() example using only one default input f(1) example of a named input f(y=1)

Named inputs def f(x=2, y=11): return x + 3*y f(3,1) f() f(3) Try this on the back page first… f(3,1) f() f(3) f(y=2,x=1) What will these function calls to f return? None of the above are 42! What call to f returns the string 'Lalalalala' ? What is f( ( ), (1,0) ) ? These are tuples – they work like lists! What is the shortest call to f returning 42? it's only four characters! Extra… what would this return? x=12; y=6; f(y=x,x=y)

Named inputs def f(x=2, y=11): return x + 3*y f(3,1) f() f(3) Input your name(s) = ___________________________ f(3,1) f() f(3) f(y=2,x=1) What will these function calls to f return? None of the above are 42! What call to f returns the string 'Lalalalala' ? What is f( ( ), (1,0) ) ? These are tuples – they work like lists! What is the shortest call to f returning 42? it's only four characters! Extra… what would this return? x=12; y=6; f(y=x,x=y)

feedback feedback Next is: 13112221

VPython www.vpython.org Where were we... ? stonehenge.py built by and for physicists to simplify 3d simulations bounce.py lots of available classes, objects and methods in its API 80-90% easily installable for windows and macs...?!

Installing VPython Windows & Mac OS Tutorials and documentation… or, use the lab's machines… Windows & Mac OS Tutorials and documentation…

API ... stands for Application Programming Interface a programming description of how to use a software library A demo of VPython's API: What's visual? What's cylinder? What's c? What's main? What's that last line? at least it's not Visual C… VPython example API calls: must be from a file

shapes! API constructors + methods! ... stands for Application Programming Interface constructors + methods! shapes!

... stands for Application Programming Interface API ... stands for Application Programming Interface

VPython Set up world with 3d objects… b = box() b.color = color.red # 1: change colors… color.red or a tuple # 2: add objects scene.autoscale = False c = cylinder(pos=(4,0,0)) a = sphere(pos=(0,0,4)) Then, run a simulation using those objects… more objects and API calls while True: rate(30) # times/sec print "b.pos is", b.pos # 3: change position (most will be added before the while loop) # 4: define velocity (above loop) # 5: then, change pos (in loop) if __name__ == "__main__": main()

let's compare with tuples… vectors b.pos, b.vel,… are vectors b.vel = vector(1,0,0) vel.z named components vel.y vel.x b.pos = vector(0,0,0) scalar multiplication b.pos = b.pos + b.vel*0.2 component-by-component addition let's compare with tuples…

vectors act like "arrows" http://vpython.org/contents/docs/vector.html

lots of support… (don't write your own) vectors lots of support… (don't write your own) http://vpython.org/contents/docs/vector.html

vpython.org/contents/docs Documentation!

Let's run it! vPython! from visual import * def main(): (1) How many vPython classes are used in this code? ____ (2) How many vPython objects are used here? ________ (3) What line of code handles collisions ? (4) How does physics work? Where is it? (5) Tricky! How many tuples are here? Look over this VPython program to determine from visual import * def main(): """ docstring! """ floor = box(length=4,width=4,height=0.5,color=(0,0,1)) ball = sphere(pos=(0,8,0),radius=1,color=color.red) ball.vel = vector(0,-1,0) RATE = 30 dt = 1.0/RATE while True: rate(RATE) ball.pos += ball.vel*dt if ball.pos.y < ball.radius: ball.vel.y *= -1.0 else: ball.vel.y += -9.8*dt Physics is here. Let's run it! what is this += doing? what is this if/else doing?

vPython! from visual import * def main(): """ docstring! """ (1) How many vPython classes are used in this code? ____ (2) How many vPython objects are used here? ________ (3) What line of code handles collisions ? (4) How does physics work? Where is it? (5) Tricky! How many tuples are here? Look over this VPython program to determine from visual import * def main(): """ docstring! """ floor = box(length=4,width=4,height=0.5,color=(0,0,1)) ball = sphere(pos=(0,8,0),radius=1,color=color.red) ball.vel = vector(0,-1,0) RATE = 30 dt = 1.0/RATE while True: rate(RATE) ball.pos += ball.vel*dt if ball.pos.y < ball.radius: ball.vel.y *= -1.0 else: ball.vel.y += -9.8*dt Physics is here. what is this += doing? what is this if/else doing?

(bounce.py + billiard_bounce.py) Lab 11 goals (0) Try out VPython! (1) Make a few changes to the starter code (2) Implement walls and wall-collisions… (3) Improve your alien and world! (Ex.) Add scoring, enemies, or a moving target, hoops, traps, holes, etc. ~ your own game… (bounce.py + billiard_bounce.py) final project option

frames What's what?

Collisions… billiard_bounce.py

key presses…

other vPython examples…

other vPython examples… Try out vPython in lab this week! ~ if you enjoy it, consider it for a final project (next Tues. is the overview of the projects)

vPython! from visual import * def main(): """ docstring! """ (1) How many vPython classes are used in this code? ____ (2) How many vPython objects are used here? ________ (3) What line of code handles collisions ? (4) How does physics work? Where is it? (5) Tricky! How many tuples are here? Look over this VPython program to determine Physics is here. from visual import * def main(): """ docstring! """ floor = box(length=4,width=4,height=0.5,color=(0,0,1)) ball = sphere(pos=(0,8,0),radius=1,color=color.red) ball.vel = vector(0,-1,0) RATE = 30 dt = 1.0/RATE while True: rate(RATE) ball.pos += ball.vel*dt if ball.pos.y < ball.radius: ball.vel.y *= -1.0 else: ball.vel.y += -9.8*dt what is this += doing? what is this if/else doing?

Next time! An AI for Connect Four

"force arrow" in example code… Orbiting example "force arrow" in example code… from visual import * e = sphere(pos=(0,0,10),color=color.blue) #earth s = sphere(color=color.yellow,radius=2) #sun e.vel = vector(5,0,0) # initial velocity RATE = 50 dt = 1.0/RATE k = 70.0 # G! while True: rate(RATE) diff = s.pos - e.pos # vector difference force = k*diff/(mag(diff)**2) # mag e.vel += dt*force # acceleration d.e. e.pos += dt*e.vel # velocity d.e. now, with vectors!