Object-Oriented Programming with Java, Spring 2008

Programming Assignment 1c - An Example Solution


Table of Contents

tblfcntnts()

Introduction

This page presents a solution to the third programming assignment, which required a program that played some number of solitaire games and reports on the results. Familarity with the example solution to the second assignment may be helpful in understanding this page. The only manditory command-line argument is a non-negative integer giving the number of games to play. For interest, there are two other optional command-line arguments:
  1. -s n: Use the integer n as the seed for the random-number generator used to shuffle the card decks. The default seed is based on the time.

  2. -p s: Play the games using strategy s, which can be one of random (the default), biased, or strongBiased.

Once everything’s squared away, let the games begin.

Playing Strategies

The design document for the Eagle's-Wing player describes three strategies: The play strategies are implemented with the template pattern using Java 5's enumeration type. The GamePlayStyles class defines the abstract play() method, which is implemented as appropriate by each member of the enumeration.

The main advantage of using enums, apart from a neat implementation of the template pattern, is using the valueOf() enum method to map between a string representing the play style and the associated enum.

Random-Play Strategy

Random-play strategy plays any possible move at any time, a simple strategy to implement given the pair iterator implemented in the CardPiles class.

Biased-Play Strategy

Biased-play strategy favors moves involving foundation piles over other moves. Biased play in favor of foundation piles makes a pass through all possible moves, making each that involves foundation piles and ignoring the rest. Biased play against foundation piles is just the opposite: make any move not involving foundation piles.

Strong-Biased-Play Strategy

Strong-biased play improves on biased play by increasing the bias towards moves containing foundation piles. A strong bias towards foundation-pile moves keeps passing through all possible moves utill there are no more foundation-pile moves possible. A strong bias against non-foundation-pile moves quits searching for moves after the first successful non-foundation move is found. In addition, because it's always possible to move cards between the stock and waste piles, the search for non-foundation moves also excludes waste- and stock-pile moves. If no other non-foundation moves are found then the apropriate stock-waste move is made as a last resort. And that's about it; the rest is utility.

Index


This page last modified on 31 March 2008.

Creative
    Commons License

m4_include(/export/home/uf/rclayton/lib/html/skel-tail.html)