Lab 1. CS 5233 Fall 2007 assigned August 22, 2007 Tom Bylander, Instructor due midnight, Sept. 26, 2007

Similar documents
For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.

CS Project 1 Fall 2017

Activity 6: Playing Elevens

CSE 231 Fall 2012 Programming Project 8

FreeCell Puzzle Protocol Document

CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 8

Lab Exercise #10. Assignment Overview

Homework Assignment #1

CS Programming Project 1

ECE2049: Foundations of Embedded Systems Lab Exercise #1 C Term 2018 Implementing a Black Jack game

Spring 06 Assignment 2: Constraint Satisfaction Problems

Spring 06 Assignment 2: Constraint Satisfaction Problems

CS 152 Computer Programming Fundamentals Lab 8: Klondike Solitaire


PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

A. Rules of blackjack, representations, and playing blackjack

Acing Math (One Deck At A Time!): A Collection of Math Games. Table of Contents

A Rule-Based Learning Poker Player

COMP 9 Lab 3: Blackjack revisited

10 Game. Chapter. The PV Unit comes with two built-in games for your enjoyment. The games are named Game-1 and Game-2.

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

Name: Checked: jack queen king ace

Free Cell Solver. Copyright 2001 Kevin Atkinson Shari Holstege December 11, 2001

CSCI 4150 Introduction to Artificial Intelligence, Fall 2004 Assignment 7 (135 points), out Monday November 22, due Thursday December 9

Math 1111 Math Exam Study Guide

Programming Assignment 4

CMPUT 657: Heuristic Search

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

Chapter 2 Integers. Math 20 Activity Packet Page 1

Problem Set 4: Video Poker

THE NUMBER WAR GAMES

Assignment 12 CSc 210 Fall 2017 Due December 6th, 8:00 pm MST

Game Playing in Prolog

Diet customarily implies a deliberate selection of food and/or the sum of food, consumed to control body weight.

GAMBLING ( ) Name: Partners: everyone else in the class

CMPSCI 240: Reasoning Under Uncertainty First Midterm Exam

CMSC 201 Fall 2018 Project 3 Sudoku

{ a, b }, { a, c }, { b, c }

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

Up & Down GOAL OF THE GAME UP&DOWN CARD A GAME BY JENS MERKL & JEAN-CLAUDE PELLIN ART BY CAMILLE CHAUSSY

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

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

CS 241 Data Organization using C. Project: Identifying the Rank of a Poker Hand and an Empirical Calculation of Probabilities

Experiment 3. Direct Sequence Spread Spectrum. Prelab

Lab 2. CS 3793/5233 Fall 2016 assigned September 13, 2016 Tom Bylander, Instructor due midnight, September 30, 2016

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

Today s Topics. Sometimes when counting a set, we count the same item more than once

Montage Baseline Background Correction

Pay attention to how flipping of pieces is determined with each move.

Project 2 - Blackjack Due 7/1/12 by Midnight

Name: Checked: Answer: jack queen king ace

Activity 1: Play comparison games involving fractions, decimals and/or integers.

Venn Diagram Problems

CSEP 573 Applications of Artificial Intelligence Winter 2011 Assignment 3 Due: Wednesday February 16, 6:30PM

Math 1111 Math Exam Study Guide

Problem A. Worst Locations

Unimelb Code Masters 2015 Solutions Lecture

BRIDGE is a card game for four players, who sit down at a

CSE231 Spring Updated 04/09/2019 Project 10: Basra - A Fishing Card Game

2 The Universe Teachpack: Client/Server Interactions

Finite Mathematical Structures A

Cards: Virtual Playing Cards Library

Spring 2007 final review in lecture page 1

CMPT 310 Assignment 1

P a g e 1 HOW I LEARNED POKER HAND RANKINGS

CHAPTER 649a. THREE CARD POKER

Tac Due: Sep. 26, 2012

LESSON 3. Third-Hand Play. General Concepts. General Introduction. Group Activities. Sample Deals

BLUFF WITH AI. CS297 Report. Presented to. Dr. Chris Pollett. Department of Computer Science. San Jose State University. In Partial Fulfillment

Poker Hands. Christopher Hayes

CS 237 Fall 2018, Homework SOLUTION

LEARN HOW TO PLAY MINI-BRIDGE

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

2. A separate designated betting area at each betting position for the placement of the ante wager;

LESSON 2. Objectives. General Concepts. General Introduction. Group Activities. Sample Deals

HIGH CARD FLUSH 1. Definitions

Freecell Solver - Evolution of a C Program. Shlomi Fish

Assignment II: Set. Objective. Materials

CS 787: Advanced Algorithms Homework 1

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

To play the game player has to place a bet on the ANTE bet (initial bet). Optionally player can also place a BONUS bet.

AP Computer Science Project 22 - Cards Name: Dr. Paul L. Bailey Monday, November 2, 2017

Crapaud/Crapette. A competitive patience game for two players

DELIVERABLES. This assignment is worth 50 points and is due on the crashwhite.polytechnic.org server at 23:59:59 on the date given in class.

Lab Assignment 3. Writing a text-based adventure. February 23, 2010

Maryland State Lottery and Gaming Control Agency Standard Rules Criss Cross Poker

G52CPP Lab Exercise: Hangman Requirements (v1.0)

Problem A. Jumbled Compass

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

5.8 Problems (last update 30 May 2018)

GIS Programming Practicuum

UMBC 671 Midterm Exam 19 October 2009

LESSON 4. Eliminating Losers Ruffing and Discarding. General Concepts. General Introduction. Group Activities. Sample Deals

Reading 14 : Counting

Smyth County Public Schools 2017 Computer Science Competition Coding Problems

Comp th February Due: 11:59pm, 25th February 2014

FAST ACTION HOLD EM. Copy hand-- means a five-card hand of a player that is identical in rank to the five-card hand of the dealer.

Date. Probability. Chapter

Transcription:

Lab 1 CS 5233 Fall 2007 assigned August 22, 2007 Tom Bylander, Instructor due midnight, Sept. 26, 2007 In Lab 1, you will program the functions needed by algorithms for iterative deepening (ID) and iterative deepening A* (IDA*) for playing Freecell. You will compare the performance of the search algorithms and the heuristic functions. Freecell Freecell is a solitaire card game commonly found on machines with MS Windows operating systems. A typical card deck has 52 cards, distinguished by 4 suits (spades, hearts, clubs, and diamonds) and 13 ranks (ace, 2 10, jack, queen, and king). In our version of Freecell, the task can be simplified by specifying a smaller number of ranks. The object of the game is to move all the cards to the four home cells, using the four free cells as place holders. To win, you make four stacks of cards on the home cells: one for each suit, stacked in ascending order of rank. Our version of freecell will stop the game sooner, when all columns are in descending order of rank. The Freecell game area consists of the four home cells, four free cells, and the deck of cards, which is dealt face-up in eight columns at the beginning of the game. With 52 cards, four columns will have seven cards, and four columns will have six cards. There are three ways you can move cards in Freecell: 1. Any card from the bottom of a column can be moved to an empty free cell. 2. A card in a free cell or the bottom of a column can be moved to a home cell if it is an ace or if the card with the same suit and next lowest rank has been moved to its home cell. 3. A card in a free cell or the bottom of a column can be moved to the bottom of another column if the column is empty or if the current bottom of the column has a different color and the next highest rank. Environment The environment program for Freecell is in /home/bylander/agents/sun/bin/freecell. 1 The source for this program and other programs are in the /home/bylander/agents/sun/src directory and in /home/bylander/agents/agents.tar. This was developed in Linux. For the Sun version, I made some minor changes to the Makefile in agents.tar so it would properly compile and install on the Suns. Also, for the CS Sun network, I used /usr/local/bin/make (GNU make) rather than /usr/ccs/bin/make (SunOS make). To run the environment with user input, do the following: 1 This is the binary for our Sun Lab. Replace sun with linux for our Linux Lab. I hope to have a windows version soon. 1

setenv A /home/bylander/agents/sun/bin or A=/home/bylander/agents/sun/bin $A/interact "$A/freecell -v" $A/freecell user You will see the 4 empty free cells and 4 empty home cells, and the 8 columns of cards. The freecell program accepts a line of two characters as input, the first character specifies the column or cell from which a card is taken. The second character specifies the column or cell to which the card is moved. 1-8 specifies one of the 8 columns. A-D (or a-d) specifies one of the four free cells. F (or f) and H (or h) can only be used as the second character. F can be used to move to the first empty free cell. H (or h) specifies a move to the home cell of the card s suit. The interact program reads the stdout of each program and sends it to the stdin of the other program. Any output to stderr will be displayed to the user. There are two exceptions. If the user types in a line, this line will be sent to both programs with the prefix user. If the interact program reads a line from a program that starts with user, then that is displayed to the user and not sent to the other program. You do not need to understand the interact program, but it might be an instructive exercise in learning Perl. Do not change interact. It has been carefully written so that it won t be the cause of any deadlock. For the Freecell game, freecell user has been written to minimally interact with the freecell program. It is instructive to run freecell and freecell -v by themselves to see the output of this program. Running freecell -h will provide some help. Simple programs that might be instructive for environment/agent interaction are in /home/bylander/agents/src/pickanum. Note that fflush is used after every line printed. In this directory, picknum is the environment, and guessnum is the agent. Running picknum -h will give you some help. Run the following to see the interaction between the two programs. Agent $A/interact -v $A/picknum $A/guessnum Your task is to write an agent program to interact with the freecell environment program. Your program will read the initial state, find a sequence of moves/operators that goes from the initial state to a goal state, and print the sequence of operators so that the environment ends up in a goal state. We will use the iterative deepening (ID) and iterative deepening A* (IDA*) algorithms to do the search for us. Talking about ID and IDA* are lectures ahead of us on the syllabus, so what I have done is to implement ID and IDA* for you, leaving you the job to implement the functions that it needs. ID and IDA* are implemented as the functions idsearch and idastar, respectively in /home/bylander/agents/src/slide/idastar.c and its companion header file idastar.h. You should use this code verbatim. That means don t make any changes to your copy of idastar.c and idastar.h unless you like looking for trouble. This code expects to find a definition of the State data type in state.h. One is provided for you in /home/bylander/agents/src/freece In this case, a State specifies the cards in the free cells, home cells, and columns, where each card is represented by a integer from 0 to 51. Allocating states will be done at runtime. 2

The file /home/bylander/agents/src/freecell/state.c contains the basic functions for allocating and freeing states. The initial state should be created by calling freecell alloc and initializing the values of the game area to the initial state. The idsearch and idastar functions are called with the initial state and the 4 functions below, one of which has already been implemented for you. See /home/bylander/agents/src/slide/8-puz for an example (the call to idastar can be replaced with idsearch). A little more documentation can be found in idastar.h. 1. freecell expand. This function inputs a state and returns an array of states that can be reached in one move. I.e., each state in this array differs from the given state by one move. It is up to freecell expand to allocate new space for the array. The last element of the array should be set to NULL. 2. freecell free. This is implemented for you in state.c. 3. freecell goal. This inputs a state and should return 1 if the state is a goal state, otherwise it should return 0. The ID algorithm will take care of finding the optimal path to a goal state. 4. freecell equal. This inputs two states and should return 1 if they are equal, otherwise 0. Two states are equal if they have the same configuration of cards. The order of cards in the free cells do not matter. 5. freecell cost. This function inputs two states and returns the cost of the edge from the first state to the second state. For Lab 1, this function should always return 1. This function is ignored by idsearch. 6. freecell heuristic. This functions inputs a state and returns an estimate of how many moves are needed to reach a goal state. This function is ignored by idsearch. Here are one idea to implement a heuristic function. The goal for our version of freecell is to put each column in descending (but not strictly descending) order. For each column, determine how many cards need to be removed before the remaining cards in the column are in descending order. At least this many moves must be made from this column. The heuristic is to add up these numbers for the columns. It will be interesting to test of version of this heuristic which simplies multiplies the result by 2. These functions will be passed as arguments to the idsearch and idastar functions. Again see /home/bylander/agents/src/slide/8-puzzle.c for an example. You might find the function implemented in /home/bylander/agents/src/split stdin.c to be useful. The split stdin function parses a line of stdin into an array of strings. Again see the 8-puzzle example. The freecell program has an -r option to control the difficulty of the problem. This options specifies the highest card rank to be used. Debug using -r 3, then try higher values until your program takes too long to run. Use the -s option to set the random number seed, so that you can debug and compare performance on the same instance(s). You should be able to run your programs with command lines like: 3

$A/interact "$A/freecell -r 3"./lab1id $A/interact "$A/freecell -r 3"./lab1ida1 $A/interact "$A/freecell -r 3"./lab1ida2 I know there are a number of things to digest before anything will run. I will be providing additional help based on the questions I get from the class. Performance Analysis For performance analysis, I would like you to measure and prepare a report on the following: 1. For idsearch: (a) Measure the number of calls to idsearch. This can be measured by including a counter in the freecell goal function because each call to idsearch makes one call to freecell goal. (b) Measure the CPU time (preferably not clock time) that is used by idsearch to do the search. In C, use the clock function. (c) Record the length of the optimal solution path. 2. For idastar and each heuristic you implement: (a) Measure the number of calls to dfs contour. This can be measured by including a counter in the freecell heuristic function because each call to dfs contour makes one call to freecell heuristic. (b) Measure the CPU time (preferably not clock time) that is used by your Lab 1 program to do the search. In C, use the clock function. (c) Record the length of the optimal solution path. Be sure to use instances that span a wide range of CPU time. Your report should comment on the performance of the different search implementations. Remember that the -r value is not the same as the length of the path from initial to final state. Also note that particular values for -r and -s on a particular machine will always result in the same instance. Turning in Your Lab Somewhere in your directory, you should create a lab1 subdirectory. This directory must have a Makefile (or must have an executable file make lab1) that compiles and links your agent programs, which must be named lab1id, lab1ida1, lab1ida2, etc. Any source code that is linked to these programs must be in this directory. That is, you should be able to copy the files in your lab1 directory to another directory and be able to run the following command sequence. 4

setenv A /home/bylander/agents/sun/bin or A=/home/bylander/agents/sun/bin /bin/rm lab1id source /etc/.login revert to default values for shell variables make or./make lab1 $A/interact "$A/freecell -m 3" "./lab1id" Your lab1 directory should have a report named lab1.html, lab1.pdf, or lab1.ps, depending on whether it is in HTML, PDF, or Postscript format, respectively. I do not want to read other special formats such as Word files, Excel files, Latex files, etc. The HTML files can link to GIF or JPG pictures in your directory. Zip or tar the entire directory and submit it using WebCT. If you submit multiple times, only the last one is kept. Be sure that WebCT has registered your submission. Grading Task Percentage of Grade ID Implementation 30% IDA* Implementation First Heuristic 10% Second Heuristic 10% Report Quality of Writing 20% Quality of Measurements 20% Quality of Conclusions 10% 5