CSC 110 Lab 4 Algorithms using Functions. Names:

Similar documents
class TicTacToe: def init (self): # board is a list of 10 strings representing the board(ignore index 0) self.board = [" "]*10 self.

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

For slightly more detailed instructions on how to play, visit:

The Mathematics of Playing Tic Tac Toe

Embedded Systems Lab

Coin Cappers. Tic Tac Toe

Unit 12: Artificial Intelligence CS 101, Fall 2018

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

This game can be played in a 3x3 grid (shown in the figure 2.1).The game can be played by two players. There are two options for players:

Intro to Java Programming Project

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

Lab 7: 3D Tic-Tac-Toe

EXPLORING TIC-TAC-TOE VARIANTS

For our EC331 project we successfully designed and implemented a PIC based Tic-Tac-Toe game using the PIC16874.

Lesson 8 Tic-Tac-Toe (Noughts and Crosses)

The game of Reversi was invented around 1880 by two. Englishmen, Lewis Waterman and John W. Mollett. It later became

1, 2,, 10. Example game. Pieces and Board: This game is played on a 1 by 10 board. The initial position is an empty board.

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

Tutorial 1. (ii) There are finite many possible positions. (iii) The players take turns to make moves.

Taffy Tangle. cpsc 231 assignment #5. Due Dates

select the 4 times tables and then all the number tiles used would be 4 x something

COSC 117 Spring 2018 Programming Project 3 Page 1 of 5. For this project, you will write a program that plays the game Tic Tac Toe.

B551 Homework 2. Assigned: Sept. 15, 2011 Due: Sept. 29, 2011

NuSMV: Planning as Model Checking

Lecture 33: How can computation Win games against you? Chess: Mechanical Turk

mywbut.com Two agent games : alpha beta pruning

OT 528: OCCUPATION-BASED TREATMENT KIT

CSE 3401 Assignment 4 Winter Date out: March 26. Date due: April 6, at 11:55 pm

ON A ROLL TO FACT FLUENCY

LEARNING ABOUT MATH FOR GR 1 TO 2. Conestoga Public School OCTOBER 13, presented by Kathy Kubota-Zarivnij

Conversion Masters in IT (MIT) AI as Representation and Search. (Representation and Search Strategies) Lecture 002. Sandro Spina

Arrays. Independent Part. Contents. Programming with Java Module 3. 1 Bowling Introduction Task Intermediate steps...

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

Game Playing in Prolog

Game, Set, and Match Carl W. Lee September 2016

Using Neural Network and Monte-Carlo Tree Search to Play the Game TEN

PROBLEMS & INVESTIGATIONS. Introducing Add to 15 & 15-Tac-Toe

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four 1

the alien has the option of asserting that all 100 aliens have been to the living room by now. If this assertion is false, all 100 aliens are thrown

CS 4700: Foundations of Artificial Intelligence

LITTLE BITES TIC TAC TOE Pair two of your favorite classics- Little Bites and Tic Tac Toe- for a game that is bound to bring back happy memories!

Artificial Intelligence Lecture 3

Due: Sunday 13 November by 10:59pm Worth: 8%

COSC 117 Programming Project 2 Page 1 of 6

Assignment 2 (Part 1 of 2), University of Toronto, CSC384 - Intro to AI, Winter

University of Amsterdam. Encyclopedia of AI project. Tic-Tac-Toe. Authors: Andreas van Cranenburgh Ricus Smid. Supervisor: Maarten van Someren

G51PGP: Software Paradigms. Object Oriented Coursework 4

1st Grade Math. Please complete the activity below for the day indicated. Day 1: Double Trouble. Day 2: Greatest Sum. Day 3: Make a Number

Assignment 2, University of Toronto, CSC384 - Intro to AI, Winter

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

COMPOSITION CRAM INSTRUCTIONS:

Interactive Tic Tac Toe

The Product Game: Playing the Product Game

General Principals. Turn Priority - this player may choose which player goes first.

ARTIFICIAL INTELLIGENCE (CS 370D)

COMP9414: Artificial Intelligence Problem Solving and Search

TIC-TAC-TOE Instruction Manual Model #7764

7 = Part-Part-Whole. Games = 6 + 1

Math 152: Applicable Mathematics and Computing

Contents. MA 327/ECO 327 Introduction to Game Theory Fall 2017 Notes. 1 Wednesday, August Friday, August Monday, August 28 6

Module 3. Problem Solving using Search- (Two agent) Version 2 CSE IIT, Kharagpur

Legend. The Red Goal. The. Blue. Goal

Real-Time Connect 4 Game Using Artificial Intelligence

The Hex game and its mathematical side

Grade 3. Summer Math Packet. This packet is optional for those students who just completed Grade 2 and who will be in Grade 3 in September.

Introduction to Spring 2009 Artificial Intelligence Final Exam

MATH GAMES THAT SUPPORT SINGAPORE MATH GRADES

A Tic Tac Toe Learning Machine Involving the Automatic Generation and Application of Heuristics

Teacher Workbooks. Mathematics Series Multiplication Starter Pack Volume Teachnology Publishing Company A Division of Teachnology, Inc.

1 Introduction. 1.1 Game play. CSC 261 Lab 4: Adversarial Search Fall Assigned: Tuesday 24 September 2013

Interactive Visualizations for Cyber-

UNIT 13A AI: Games & Search Strategies. Announcements

Lab 11: GoFirst and Nim 12:00 PM, Nov 19, 2017

Gough, John , Doing it with dominoes, Australian primary mathematics classroom, vol. 7, no. 3, pp

Object-Oriented Design

UNIT 13A AI: Games & Search Strategies

GAMES COMPUTERS PLAY

Project Connect Four (Version 1.1)

INSTRUCTIONS MATERIAL YOU WILL NEED FOR THIS ACTIVITY:

CPSC 217 Assignment 3

Tic-Tac-Toe and machine learning. David Holmstedt Davho G43

by Teresa Evans Copyright 2005 Teresa Evans. All rights reserved.

Mastering the game of Omok

Grade 7/8 Math Circles November 24/25, Review What have you learned in the past seven weeks?

INTRODUCTION TO GAME THEORY

Game Theory and Algorithms Lecture 19: Nim & Impartial Combinatorial Games


Math 152: Applicable Mathematics and Computing

Caterpillar Chase. Race to the Finish. On the Ferris Wheel

Movement of the pieces

Modeling Strategic Environments 1 Extensive form games

Playing Games. Henry Z. Lo. June 23, We consider writing AI to play games with the following properties:

CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #5

3. If you can t make the sum with your cards, you must draw one card. 4. Players take turns rolling and discarding cards.

2 person perfect information


Games (adversarial search problems)

CMPUT 396 Tic-Tac-Toe Game

(Provisional) Lecture 31: Games, Round 2

Transcription:

CSC 110 Lab 4 Algorithms using Functions Names: Tic- Tac- Toe Game Write a program that will allow two players to play Tic- Tac- Toe. You will be given some code as a starting point. Fill in the parts of the main algorithm and the functions to make the program work. How it works The game board is represented by a list where each position in the list represents a spot on the board: 0 1 2 ---------------- 3 4 5 ---------------- 6 7 8 So we have the list: where the first three elements of the list (bd[0], bd[1], bd[2]) represent the first row of the board, the second three elements (bd[3], bd[4], bd[5]) represent the second row of the board. And the last three elements (bd[0], bd[1], bd[2]) represent the bottom row. If you want to fill in a spot with an X or an O, you can replace the value in the list. So to put an X in the center square, you will use the following command: bd[4] = X Tic- Tac- Toe python code All of the code you will need for this lab can be found in this file: http://www.cs.uri.edu/~cingiser/csc110/labs/python/tictactoe_skeleton.py For the exercises below, you can open this file in a text editor or in IDLE and copy and paste the parts you need for each exercise.

Get Started Draw the board To get started, create a Python code file with the drawboard function code in it: def drawboard(board): # Draws the board using the list of numbers print(" ") print(" ",board[0]," ",board[1]," ", board[2]) print("----------------") print(" ",board[3]," ",board[4]," ", board[5]) print("----------------") print(" ", board[6]," ",board[7]," ", board[8]) print(" ") return Save the file as draw.py and then run the code. Create the board with the following command in the Python Shell: Now draw the board with the command, also in the Python Shell: drawboard(bd) In our game, this is considered an empty board because it has no X s or O s in it. It only has place holder numbers. To place a symbol in the spot on the board labeled 3, type the following command: bd[3] = X Now draw the board again to see the new board. Try a function: The nextmove function asks a player to choose a spot on the board, replaces the spot on the board with the player s symbol, and then returns the board as a result. Write this function by filling in this code:

def nextmove(turn,bd): # Ask the player to choose a spot on the board # Replace the spot on the board with the player s symbol # The turn parameter represents the player s symbol # Return the board return bd After you write the code for this function, save it in the same file where you saved the drawboard function and run the code. In the Python Shell, create the board again: Now draw the board: drawboard(bd) and then call for the next move: bd = nextmove( X, bd) and draw the board again. This will allow you to test the function before you use it in the full program. Fill in the code Now you can take the rest of the code from the tictactoe_empty.py file, along with the functions you have written and fill it in to create the program to play the game. Save your program as tictactoe.py and test it out. The main code is given in the file, along with comments to describe how it works. You are to fill in the code for the functions. Here are some hints about how to complete the rest of the functions.

moremoves This function is used to determine if there are any more spots on the board to be filled in. Think about what the board would look like if it was FULL. What kinds of values would it be full of? nextturn This function switches whose turn it is. It is given the symbol for the player whose turn it is currently, and it should return the symbol for the other player. iswinner This function is used to determine if there is a winner. In tic tac toe, there is a winner when one of the players has taken three spots in a row, horizontally, vertically or diagonally. One way to implement this is to consider all of the possible ways that a player can have three in a row with this particular board representation. For example, if the first three values in the board are equal to each other: if bd[0] == bd[1] and bd[1] == bd[2] Then whichever symbol is in those positions is the winner, and that symbol should be returned by the function.

Challenge Problem Modify the tic- tac- toe program above so that the computer plays as one of the players. If you can get it to just play, without any type of intelligence, just choosing a position on the board that is not already taken, you will get one extra point. If you can get it to play so that the computer player blocks a win by the human player, and tries to win, then you can get two extra points.