Lab 7: 3D Tic-Tac-Toe

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

CSC 110 Lab 4 Algorithms using Functions. Names:

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

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

Embedded Systems Lab

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

Tac Due: Sep. 26, 2012

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

2 Textual Input Language. 1.1 Notation. Project #2 2

COSC 117 Programming Project 2 Page 1 of 6

Tutorial: Creating maze games

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

Unit 12: Artificial Intelligence CS 101, Fall 2018

EXPLORING TIC-TAC-TOE VARIANTS

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.

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

Intro to Java Programming Project

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

Game Maker Tutorial Creating Maze Games Written by Mark Overmars

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

Coin Cappers. Tic Tac Toe

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

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

Taffy Tangle. cpsc 231 assignment #5. Due Dates

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

Game Playing in Prolog

Words Mobile Ready Game Documentation

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.

CPM Educational Program

Version 6.1. Instructional Days: 11-14

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

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

2048: An Autonomous Solver

Cato s Hike Quick Start

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

Turtle competitions in MicroWorlds EX

Copies of the Color by Pixel template sheets (included in the Resources section). Colored pencils, crayons, markers, or other supplies for coloring.

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

CPSC 217 Assignment 3

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

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

Grade 5 Math By Kelly McCown. Summer. NO PREP Math Packet

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

Project 1: Game of Bricks

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:

Overview. The Game Idea

Experiment 7: Arrays

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

Introduction to Spring 2009 Artificial Intelligence Final Exam

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

Real-Time Connect 4 Game Using Artificial Intelligence

CS Programming Project 1

SudokuSplashZone. Overview 3

G51PGP: Software Paradigms. Object Oriented Coursework 4

Introduction to Computing 2014 Assignment 4 (Preliminary Version) Simple Checkers Game

CSE 115. Introduction to Computer Science I

Physics 310 Escape the Potential: Rulebook A Card Game of Quantum Immersion

Final Project: Reversi


Star Defender. Section 1

COMP 9 Lab 3: Blackjack revisited

SCRABBLE ARTIFICIAL INTELLIGENCE GAME. CS 297 Report. Presented to. Dr. Chris Pollett. Department of Computer Science. San Jose State University

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

CS 4700: Foundations of Artificial Intelligence

Introduction to Computer Science with MakeCode for Minecraft

SMART 3 IN 1 HOLLYWOOD PHOTOS: SETTING UP YOUR BOOTH FOR WEDDING/EVENT MODE

Project Connect Four (Version 1.1)

Legend. The Red Goal. The. Blue. Goal

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

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

Hackenbush. Nim with Lines (and something else) Rules: Example Boards:

isudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

PATTERN MAKING FOR THE INFINITY WAND

InfoSphere goes Android Angry Blob

Introduction to ABB Labs. TA s: Ryan Mocadlo Adam Gatehouse

CS 211 Project 2 Assignment

Hexagons for Art and Illusion Part II Get ready Start a new project FILE New Open Faced Cube Import the hexagon block LIBRARIES

BMT 2018 Combinatorics Test Solutions March 18, 2018

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

Numan Sheikh FC College Lahore

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

How hard are computer games? Graham Cormode, DIMACS

Figure 1: The Game of Fifteen

Mind Ninja The Game of Boundless Forms

CS1301 Individual Homework 5 Olympics Due Monday March 7 th, 2016 before 11:55pm Out of 100 Points

(Provisional) Lecture 31: Games, Round 2

Create Your Own World

Final Project: Verify a Sudoku Solution Due Fri Apr 29 (2400 hrs)? Wed May 4 (1200 hrs)? 1

03/05/14 20:47:19 readme

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

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

PLAYERS AGES MINS.

pla<orm-style game which you can later add your own levels, powers and characters to. Feel free to improve on my art

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #7. Project #1: Checkers, Due: Feb. 19th, 11:59p.m.

AP Art History Flashcards Program

More Activities to Reinforce and Teach Sight Words

COMPUTING CURRICULUM TOOLKIT

The Mathematics of Playing Tic Tac Toe

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

Journey through Game Design

Transcription:

Lab 7: 3D Tic-Tac-Toe Overview: Khan Academy has a great video that shows how to create a memory game. This is followed by getting you started in creating a tic-tac-toe game. Both games use a 2D grid or array to represent the game state. In this lab, you will be creating a 3D game of Tic-Tac-Toe. However, you will NOT be doing 3D graphics. Think of 3D Tic-Tac-Toe as just 3 different 2D tic-tac-toe games. You will draw three 2D boards on the canvas and the player will make a move each turn in one of the three boards. A player wins when getting three-in-a-row in the usual way on any one of the three levels. A player can also win by getting three-in-a-row vertically, either in a single column or on a diagonal. Additionally, the middle space on the middle level is banned. For example, each board below shows a win case for player 0: You are free to choose the style in which you draw the three layers of the 3 3 3 3D tac-tac-toe board. The two on the left are examples I coded in JavaScript. The first is very basic, but meets all the requirements. The second has more style, and is drawn using just the 2D JavaScript/Processing primitives we have been working with this semester. The X and O sprites are images I created in Photoshop. I have posted the image files on the website. If you want to use images, you may use those or use some third party asset or draw your own. The second example highlights the winning cells with a darker background and brighter, thicker boarder. When the player or AI wins, your program is required to recognize and report the win, but it is not required that there is a graphic element to the reporting. -1 of 8-

Visualizing the board: This is a photo of a 3D tic-tac-toe game made from 4 long bolts, 4 rounded top thumb bolts, three acrylic trays, 14 amber colored marbles and 14 green colored marbles. The whole thing assembles and disassembles in a few minutes and fits in a box that is the length of one bolt, the width of one tray and the height of a tray plus a marble. To start off, imagine the board as a cube of layered 2d tic-tac-toe boards. To write JavaScript code for this, it is very useful to invent a naming system that allows each space to be unambiguously identified. There is more than one possible naming system that could work, but each programmer should pick one and use it throughout his or her program. The naming system used on the right is the system used in the example code on the class website. This system has some nice properties that make it easy code in JavaScript. For example, on each of the three levels, cells 0, 1 and 2 are a win, as are cells 6, 7 and 8. Indeed, even 3, 4, and 5, if they all match, are a win on every level. Of course, cell 4 on board2 is an illegal move, but the simplest way to implement that is by filling board2 cell 4 at the start of the game with something that is NOT blank, NOT X and NOT O. -2 of 8-

The 36 Possible Ways to Win (by UNM student/lab instructor Ben Matthews ): Grading Rubric [20 points total]: [Web Site: 3 point]: In Blackboard Learn, submit a link to a web page you create that runs your working game. [Drawing the Board: 2 points]: Draw a set of 3 tac-tac-toe boards with the middle board missing the middle spot. [Getting Input: 2 points]: When it is the user s turn, and the user clicks on an empty spot, your board draws an X in that spot. Be sure to use the Khan Academy video on the memory game as it will help greatly with this. [No Cheating: 3 points]: Each AI turn, your AI must make a legal move and the game must always prevent the player from making an illegal move (For example, an illegal move is to move in a location already taken or in the center location of the middle board). [Recognizing a Win: 4 points]: Your game must recognize when either the player or the AI has attained three-in-a-row, must report the winner and must query for a new game. -3 of 8-

[Taking a Win: 3 points]: Your AI does not need to be super smart; however, if the AI can win on its current turn, then the AI must make a winning move. [Blocking a Win: 3 points]: If your AI cannot win in a single move, and the player can win on his or her next move, then the AI must block at least one possible three-in-a-row that the player could make. Spoilers: On the class website, there are 4 sample programs we developed in class: TicTacToe1_KahnAcademy.html TicTacToe2_CheckSomeWins.html, TicTacToe3_ColorSomeWins.html, TicTacToe4_AI.html, TicTacToe5_MultiBoard.html TicTacToe1_KahnAcademy.html is the code you get when you work through the Khan Academy video. The data structure used in TicTacToe1_KahnAcademy.html to represent the board is an array of Tile objects, called tiles. It is a global field populated in the setup function: for (var i = 0; i < NUM_COLS; i++) { for (var j = 0; j < NUM_ROWS; j++) { var x = i * (canvaswidth/num_cols-1); var y = j * (canvasheight/num_rows-1); tiles.push(new Tile(x, y)); } } This nested loop pushes each new Tile into the tiles array such that the first element of the array, tiles[0], is the tile in the upper right of the board. The second element of the array, tiles[1], is in the second row of the first column, etc.: 0 3 6 1 4 7 2 5 8 Check Win Spoiler: The second, checks for **some** ways of winning and all it does is print Winner in the debug console. To fully make this work you can do these things: 1) Check for all the other ways to win. 2) When a win is found, have the code do two things: Display some game over or winner message on the canvas. This message could be drawn superimposed the board or above, to the side or below. Also, set a global field, say for example, gameover to true. -4 of 8-

3) In the given example, the draw() function always fills the canvas with the background color (erasing everything) and then redraws the board. You will want to change the draw() function to check the new gameover field and if gameover===true, then return without erasing or drawing anything. Also, now that draw() no longer calls drawtiles() when the game is over, you need to call drawtiles() from the place where your code finds the win. The tiles need to be drawn AFTER the winning move is made and BEFORE the winner message is displayed. 4) In the mousereleased() function check the new gameover field and if gameover===true, then restart the game. One way to do this is to reload the page. Another way to restart the game is to loop through all the tiles, set every tile s label to the empty string ( ) and set gameover=false. This will restart the game because 1/60 of a second later, when draw() is called, the board will be erased and all the cells will have been cleared. TicTacToe3_ColorSomeWins.html: This example shows how to do something that is not a requirement, but nice: when the game finds a win, it draws in bright green whichever symbols that are three-in-a-row. This is done by adding a new field to the Tile object: this.partofawin. When each tile object is created, this new field is set to false. When the method that checks for a win finds a win, it sets this field to true for each tile that is part of the win. AI Kickstart Spoiler: The third sample code has some basic AI working. In this example, inside the mousereleased() function, if and only if the player successfully makes a move (clicks in a cell that is not already occupied), then the player has finished a move so a new function, makeaimove() is called. The new function, makeaimove() has a loop. Each iteration of the loop picks a random tile and tries to move there. If the tile is empty, the move is made and the loop exits. AI GameOver Spoiler: There are three ways for the game to end: Player X gets 3 in a row, Player O gets 3 in a row, and when all cells are full. Your AI must recognize all three of these cases. For example, the given AI will get stuck in an infinite loop if all the spaces are full. It will forever keep picking random spaces and keep finding the space is not empty over and over again (until the computer burns out or some human closes the webpage). One way recognize when the board is full is to add a global field set initially to the number of cells on the board. Then, whenever the player or the AI makes a move, decrement that field. After each move, check the value of the field. If it is zero, then there are no empty cells left, the game is over. Thus, display a Game Over message on the canvas and set the gameover field to true. AI Takes a Win Spoiler: The given kickstart AI makes a random move (on the first board only since this version only has one board). This code for making a random move should be at the end of your improved makeaimove() function. The first part of your function should -5 of 8-

check if a one-move win is possible and, if so, make (or block) that move. I suggest writing a new method, perhaps called : checkforonemovewin(tileidx, playersymbol) I suggest passing the player symbol as an argument so that the same function can be used by the AI to check if it can win in a single move and if not, it can also be used to check if the human player can win in a single move. Later, when you add three boards, you might change this function to: checkforonemovewin(board, tileidx, playersymbol) This function should return true if the tile at tileidx is empty and the given player symbol, if placed there, will make three-in-a-row. Otherwise, it should return false. Once you have this function, update makeaimove() to loop through each of the tiles and if the check for win function, called with the symbol O ever returns true, then make the move. AI Block Win Spoiler: This is easy, once you have the above step working. If the AI could not find a place to move to win, then repeat the same loop only call the check of win function with the player symbol, X. Multi-board Spoiler: The multi-board sample code we developed in class does some, but not all of the stuff you need: It draws three boards with a nice space between each. It creates a list of the cells in each board so that it can keep track of moves on all three boards. It recognizes when the player clicks in any cell of any of the three boards and draws the player symbol in the correct space of the correct board. It sets the center cell of the center board to a label that is not X, not O and not empty. It then, in Tile.prototype.draw() if the cell has that invalid symbol, it draws that cell in the background color and returns. That is a start, but there is more to do. In particular, the AI needs to move on all three boards, three-in-a-row needs to be checked on all three boards AND, having three boards makes totally new ways of making three-in-a-row (such as cell 0 of all three boards or cell 2 of all three boards,...). Note: the example code puts each board in a different variable: board1, board2 and board3. Then, all the places where it uses board1, it also repeats with board2 and -6 of 8-

board3.that works, but it makes for lots of repeated code. If you can handle the abstraction, you can make your code much shorter by making a variable: boardlist = [board1, board2, board3]; With that, rather than repeating all the code with each board, you can just loop through the boardlist[] array. Extra Credit: [Getting Smarter: +5]: Make your AI significantly smarter than the base requirement. Here are some suggestions for how to make your AI smarter: 1) Play the corners first: Just like in regular 2d tic-tac-toe, the corners are the most valuable space, because they have the most win lines that emanate out from them. 2) Play next to a move you played before: You can make the AI stronger by having it pick a particular direction it wants to move in and continue to play along that line until it gets blocked. 3) Block before the last minute: The basic AI will wait until the last move before a win to block a win line. You can make this better by searching for lines that are only missing 2 spaces as well as just one. [Wizard: +5]: After earning the +5 for Getting Smarter, make your AI even smarter by adding yet another key strategy. [Polish: up to +10]: A normal credit program needs to draw a board with lines, and shapes that get drawn in response to user actions. A well-polished program has the perfect lines and the perfect shapes that are summoned into existence not just when required, but with style to really make the user experience pop. -7 of 8-

[4 4 4: +20]: Replace the 3 3 3 game requirements with a program that plays 4 4 4 Tac-Tac-Toe AND teach it to play at the Wizard level as defined above for the 3 3 3 game. Note, 4 4 4 Tac-Tac-Toe does not have any banded spots on any levels. The 4 4 4 layout shown above is not required for this extra credit option. You are free to come up with your own layout. This example layout is nice in that it gives the 3D appearance without using any 3D graphics: The vertical are drawn at an angle on top of a solid blue rhombus with simple, slightly slanted images for the Xs and Os. -8 of 8-