The Darwin Game 2.0 Programming Guide



Similar documents
The Darwin Game 2.2 Player s Handbook

Debugging Java Applications

For Introduction to Java Programming, 5E By Y. Daniel Liang

Java CPD (I) Frans Coenen Department of Computer Science

<Insert Picture Here> What's New in NetBeans IDE 7.2

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Challenges in Android Application Development: A Case Study

Java with Eclipse: Setup & Getting Started

Dashboard Builder TM for Microsoft Access

Part 1 Foundations of object orientation

CS 209 Programming in Java #1

Tutorial: Getting Started

Analysis of Micromouse Maze Solving Algorithms

Using Karel with Eclipse

How to Install Java onto your system

Installing the Android SDK

Website Development Komodo Editor and HTML Intro

User Tutorial on Changing Frame Size, Window Size, and Screen Resolution for The Original Version of The Cancer-Rates.Info/NJ Application

mouse (or the option key on Macintosh) and move the mouse. You should see that you are able to zoom into and out of the scene.

Installing and using XAMPP with NetBeans PHP

IOIO for Android Beginners Guide Introduction

Hypercosm. Studio.

CA Nimsoft Monitor. Probe Guide for E2E Application Response Monitoring. e2e_appmon v2.2 series

Tivoli Endpoint Manager BigFix Dashboard

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Desktop, Web and Mobile Testing Tutorials

CS170 Lab 11 Abstract Data Types & Objects

Fahim Uddin 1. Java SDK

Debugging Multi-threaded Applications in Windows

Designing a Home Alarm using the UML. And implementing it using C++ and VxWorks

Chapter 1. Introduction to ios Development. Objectives: Touch on the history of ios and the devices that support this operating system.

Android Environment SDK

Fundamentals of Java Programming

Android Environment SDK

Real-time Debugging using GDB Tracepoints and other Eclipse features

An Informational User Guide for: Web Conferencing

Making TIFF and EPS files from Drawing, Word Processing, PowerPoint and Graphing Programs

Citrix EdgeSight for Load Testing User s Guide. Citrx EdgeSight for Load Testing 2.7

Front-End Performance Testing and Optimization

Mocean Android SDK Developer Guide

Apple Applications > Safari

Use fireworks and Bonfire night as a stimulus for programming

How to Develop Accessible Linux Applications

Installation and User Guide Zend Browser Toolbar

Event processing in Java: what happens when you click?

Lab 0 (Setting up your Development Environment) Week 1

Download a huge range of popular boardgame rules summaries, reference sheets and player aids at

Setting Up a Windows Virtual Machine for SANS FOR526

Programming with the Dev C++ IDE

Sweet Home 3D user's guide

Make your own Temple Run game

Quick Start Tutorial Imperial version

StruxureWare Data Center Operation Troubleshooting Guide

MarkLogic Server. Connector for SharePoint Administrator s Guide. MarkLogic 8 February, 2015

How to Build a Simple Pac-Man Game

How to connect to the University of Exeter VPN service

Editors Comparison (NetBeans IDE, Eclipse, IntelliJ IDEA)

MyMathLab/MyStatLab Student User Guide

Collaborative Tools. Course groups can also use the Collaboration tools for private sessions open only to course group members.

How to Install the Cisco AnyConnect VPN Client. Installing Cisco AnyConnect VPN Client on Windows with the Chrome Browser (Recommended)

PTC Integrity Eclipse and IBM Rational Development Platform Guide

CONTENTS. What is ROBOTC? Section I: The Basics

Computer Science Concepts in Scratch

SAS BI Dashboard 3.1. User s Guide

Title: Appium Automation for Mac OS X. Created By: Prithivirajan M. Abstract. Introduction

System Architecture V3.2. Last Update: August 2015

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Introduction to Eclipse

Getting Started with Android Development

Tutorial 5: Developing Java applications

Monitoring, Tracing, Debugging (Under Construction)

Developing Algo Trading Applications with SmartQuant Framework The Getting Started Guide SmartQuant Ltd Dr. Anton B.

Getting Started With DraftSight A Guide For AEC Users

How To Use An Easymp Network Projection Software On A Projector On A Computer Or Computer

Citrix EdgeSight for Load Testing User s Guide. Citrix EdgeSight for Load Testing 3.8

Advanced Programming with LEGO NXT MindStorms

1 ImageBrowser Software Guide

Instrumentation Software Profiling

Wakanda Studio Features

EasyMP Network Projection Operation Guide

SANbox Manager Release Notes Version Rev A

Before you can use the Duke Ambient environment to start working on your projects or

IDS 561 Big data analytics Assignment 1

Mail Programming Topics

Example of Standard API

Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13

Apple Time Machine. Backing up. Setting up Time Machine

Quick Start Tutorial Metric version

How to Create an Android Application using Eclipse on Windows 7

Installing Java. Table of contents

Configuration Manual English version

A Short Introduction to Writing Java Code. Zoltán Majó

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Quick Reference Guide

Guide To Creating Academic Posters Using Microsoft PowerPoint 2010

603: Enhancing mobile device experience with NetScaler MobileStream Hands-on Lab Exercise Guide

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Transcription:

The Darwin Game 2.0 Programming Guide In The Darwin Game creatures compete to control maps and race through mazes. You play by programming your own species of creature in Java, which then acts autonomously during competition. Creatures can move, sense their surroundings, and attack. A successful attack replaces its target with a new instance of the attacker, allowing creatures to reproduce. 1 The World of Darwin Darwin creatures exist in a rectangular world specified by a rectangular map. Different maps are available. A map square may be empty, occupied by a creature, or by an obstruction. Here are some of the common elements in Darwin maps: Object Type Image Description Wall Type.WALL Impassable square. Attempting to move onto this square halts but does not harm a Creature. Apple Type.CREATURE Motionless, passive Creature just waiting for you to attack it. Thorn Type.THORN Impassable square. Attempting to move onto this square converts a Creature to an Apple as if it were attacked. Flytrap Type.CREATURE Dangerous creature rooted in place. Continuously spins to the left and blindly attacks. Treasure Type.CREATURE Attack this to complete a Maze map. Morgan McGuire, 2008 Williams College Computer Science Department http://cs.williams.edu/~morgan/cs136/darwin2.0 Thanks to Aaron Size, Chris Warren, and Josh Szmajda for play testing.

2 Development If you are playing the Darwin Game in a course, your instructor has probably given you a Java development environment. If you are not in a course, or just want to work on your Creature at home, you can follow the instructions in this section. You can play the Darwin Game on any operating system, using the free Java Development Kit from Sun and any text editor, like Notepad, Emacs, code, or Visual Studio. Download the JDK from: http://java.sun.com/javase/downloads/index.jsp You can use any version of Java 5.0 or later. At the time of this writing, Java 6 Update 5 SE is the latest version. If you are on OS, Linux, or FreeBSD then Java is probably already installed on your computer. To compile a creature, type javac mycreature.java at the command prompt after installing Java. You can also use the command javac *.java to simply compile all of the files. There are several GUI integrated development environments for Java that are either available free or have a free trial period. These include Eclipse, IdeaJ, BlueJ, and NetBeans. 2/2

Winning Conditions A creature species wins a Darwin map under either of the following conditions: Only its species, Flytraps, and Apples remain live on the map The time limit is reached, it is the most populous species (ignoring Flytraps and Apples), and there are no Treasures remaining on the map. All species lose if the time limit is exceeded and there are Treasures present or there is no majority population. By convention, Maze maps with names beginning in mz_ contain only one kind of creature and Treasure (typically, one creature and one Treasure). The goal on these maps is to find and attack the treasure as fast as possible. Natural Selection maps with names beginning in ns_ contain multiple kinds of creatures and no Treasure. The goal on these maps is to convert all members of other species, or at least hold a majority when time runs out. It is possible to create maps with other goals by simply combining Treasures with multiple creature spawn points. For example a head-to-head map race could contain two creatures and two treasures in disconnected mazes. 3 Creature Actions In addition to regular Java commands for programming logic, creatures can perform actions within the world. Each action has a real-world time cost measured in time steps. All actions except for attack are effective at the end of the specified number of time steps. For example, when moving, the creature sits still for 3 time steps and then moves instantaneously. Attacks happen immediately, but then the creature is delayed for 4 time steps. Action Cost Description Move Backward Move Forward 4 Move backward one square. If the square is blocked, the move fails but still costs time. 2 Move forward one square in the current facing direction. If that square is blocked, the move fails but still costs time. Delay 1 Wait one time step without doing anything. Attack 4 Attack the creature immediately in front of this one. If there is no creature present, the attack fails but still takes time. If the attack succeeds the target is replaced with new instance of this creature facing in the opposite direction. Look 1 Return a description of the contents of the first nonempty square observed in the creature s facing direction. Turn Left 3 Rotate 90-degrees counter-clockwise. Turn Right 3 Rotate 90-degrees clockwise 3/3

4 The Darwin GUI The Darwin class runs the Simulator within a GUI. Its command line arguments are the name of the map and the Creature classes with which to populate it. An initial optional argument of -2D or -3D forces the initial view. For example, the command: java Darwin -3D ns_faceoff.txt Rover Pirate launches the simulator on the Faceoff! map with Rovers competing against Pirates. The GUI always begins paused. Press one of the three play buttons to begin simulation. The speed of simulation can be changed (or paused again) during play. The view can be switched from 2D (good for debugging) to 3D (good for watching matches) using the gray square and cube icons. Reload Pause Slow Fast Faster Population Graph 2D 3D Debugger In 2D view mode, click on any Creature to view it in the Darwin Debugger. This shows information about the Creature that updates in realtime, including the current value of its tostring method. Override tostring on your Creature and use the debugger to inspect the internal state as it moves through the map. The Reload button not only restarts the simulation, it also reloads your Creature files from the.class files. This means that if you change your Creature and recompile it, you do not need to restart the simulator! Just press reload, as if in a web browser, and you ll get the newest version. 4/4

5 Creating Maps Maps are ASCII files. The first line contains the width and height of the map and the map title, separated by spaces and terminated by a newline. The remaining lines form a picture of the map. The elements available are: ' ' Empty square '' Wall '#' Alternative color wall '+' Thorns 'f' Flytrap (which is a Creature) 'a' Apple (which is a Creature) '*' Treasure (which is a Creature) '0' '9' Spawn locations of Creature subclasses At load time, the outer border of the map is forced to be all Walls regardless of what was specified in the map file. Maze maps are named mz_mapname.txt. They contain a single Treasure (the goal) and a single 0 that is the start position. (It is possible to make mazes with multiple treasures; for these all Treasures must be attacked to win). Natural Selection ( deathmatch ) maps are named ns_mapname.txt and may have any combination of elements. The text file for the Faceoff! map is shown below. 29 29 Faceoff! 1 1 1 1 11 1 1 1 ++ + a a a a a+a a a a a + + ++ 0 0 0 00 0 0 0 0 5/5

6 API Creatures all subclass Creature, which provides a set of protected and public methods that enable the Creature to interact with the world. Creatures must either provide a public constructor of no arguments or have no constructor. The constructor cannot make the creature take an action. A Creature s run method executes when it is inserted into the world. When the run method ends the creature can take no further actions (it remains in the world, however). Therefore most Creatures have an intentionally infinite loop in their run method to allow them to continue taking actions. If a Creature is successfully and converted to another species, then it is removed from the world but continues executing. The isalive() method for a converted creature returns false. If a creature that has been converted attempts to take an action, then a ConvertedError is thrown. Most Creatures catch this error and then allow their run method to terminate. See http://cs.williams.edu/~morgan/cs136/darwin2.0/doc for the full Creature API. Below is a sample of the code for a very simple Creature called a Rover. It moves until obstructed and then attacks the obstruction and turns to the left. It is surprisingly effective, but is unable to deal with Thorns because it never looks before moving. The gray code is boilerplate common to every Creature. The bold black code in the center is the logic unique to the Rover. public class Rover extends Creature { public void run() { try { while (isalive()) { if (! moveforward()) { attack(); turnleft(); catch (ConvertedError e) { Creature positions are specified using Java.awt.Point, which you will need to import at the top of your class to perform any useful operations on positions. Note the helper methods on Creature and Direction that operate on Points and Observations. The API uses Java enum types to specify Directions and creature Types. Enum types can generally be treated as constants, however they do provide useful utility methods as well. The following (nonsense) code shows examples of how to use the Direction enum. 6/6

Direction d = Direction.NORTH; if (d == Direction.SOUTH) { d = d.left(); Point p = new Point(3, 4); p = Direction.forward(p); switch (d) { case NORTH:... break; case EAST:... 7/7

7 Images You can customize the way the Simulator renders your Creature in the 3D view by providing four images, called sprites. Each image must be in PNG format and be no larger than 40 x 60 pixels. The images must be named Creature-D.png, where D is one of N, S, E, W and Creature is the name of your creature s class. Below are four images for the Pirate Creature. Pirate-N.png Pirate-E.png Pirate-S.png Pirate-W.png Images are drawn from a 45-degree isometric perspective. NS and EW lines should be diagonals with a Y: slope of 1:2. When drawing these it often helps to look at Wall.png to get the perspective right. Since this is the perspective used for many 2D games like Age of Empires, SimCity, Diablo, and Habbo Hotel you can often use sprite images from those games (you can t publicly distribute such sprites, though, because they are copyrighted by the respective developers). A huge list of sprites ripped from 2D games can be found at http://sdb.drshnaps.com/index.htm. Sprites should have transparent backgrounds. The center of the ground square is in the horizontal center of the sprite and about 8 pixels from the bottom of the sprite. Drawing a subtle drop shadow under a sprite helps makes it appear to actually be standing on the ground. 8/8

8 Advanced Topics Each creature runs on its own thread. This means that Creatures trade comptutation time for the time that could be spent taking actions in the world. Actions take at least one millisecond to complete, so small scale efficiency will not affect most Creatures. However, if your logic is very slow, you might find that your Creature is thinking while others are moving. To communicate between multiple instances of your Creatures, create static fields to hold values and use the Java synchronized keyword to control access to them. If a static synchronized method has been invoked on a class, all other static synchronized method calls on that class block (wait) for it to complete. This ensures that two instances are not trying to read and write to a variable at the same time and is necessary for consistency. For example, the following code allows a Creature to track how many other members of its species are still alive: class Counter extends Creature { static int numalive = 0; static synchronized void changenumalive(int delta) { numalive + delta; static synchronized int getnumalive() { return numalive; public void run() { changenumalive(1); try { // Body code here catch (ConvertedError e) { // No longer alive finally { changenumalive(-1); Creatures may continue to execute after they have been converted so long as they do not take actions. This simplifies the process of performing any kind of centralized control because you can always use the first creature created to issue orders to the others. Centralized control is not necessarily worthwhile, however many creatures are very effective by allowing group behavior to emerge from simple individual actions. Creatures are allowed to open network connections, so you can control them interactively from another machine if you like. However, at full simulation speed it is almost impossible for a human to give any useful input because the Creatures move so fast. You can run the Simulator without the GUI if working at a terminal or executing offline simulations. The Simulator.toString method prints a text version of the 2D map to aid in debugging. 9/9