Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Critter World Simulation

A complete implementation of the CS 2112 Critter World simulation project.

Prerequisites

  • Java 17 or higher
  • Gradle 8.x (wrapper included)

Project Structure

src/
├── main/
│   ├── java/
│   │   ├── ast/           # AST nodes for critter programs
│   │   ├── parse/         # Tokenizer and parser
│   │   ├── model/         # World, Critter, Hex, Constants
│   │   ├── interpret/     # Rule interpreter
│   │   ├── controller/    # Controller interface + SimulationThread
│   │   ├── fxml/          # JavaFX application entry point
│   │   ├── gui/           # HexGridCanvas, MainController
│   │   ├── console/       # Console interface
│   │   ├── buffer/        # Thread-safe RingBuffer
│   │   └── a4/            # BinaryHeap for smell calculation
│   └── resources/
│       └── fxml/          # FXML layouts and CSS styles
├── test/java/             # Unit tests
examples/                  # Sample critter and world files
problems/                  # Assignment critter programs (prolific, spiral, eat-and-bud)
spec/                      # Assignment specifications (PDFs)

Building

./gradlew build

Running the GUI

./gradlew run

Running the Console

./gradlew console

Running Tests

./gradlew test

GUI Features

  • New World: Creates a random world with scattered rocks
  • Load World: Load a world definition file
  • Load Critters: Add critters from a critter file
  • Step: Advance simulation by one time step
  • Run/Pause: Start/stop continuous simulation
  • Speed Slider: Adjust simulation speed (1-100 steps/sec)
  • Click critter: View critter information (memory, program, last rule)
  • Scroll: Zoom in/out
  • Right-click drag: Pan the view

Critter Language Grammar

program   → rule rule*
rule      → condition --> command ;
command   → update* [action]
update    → mem [ expr ] := expr
action    → wait | forward | backward | left | right | eat | attack
          | grow | bud | mate | serve [ expr ]
condition → conjunction (or conjunction)*
conjunction → relation (and relation)*
relation  → expr rel expr | { condition }
rel       → < | <= | = | >= | > | !=
expr      → term (addop term)*
term      → factor (mulop factor)*
factor    → ( expr ) | number | mem [ expr ] | sensor
sensor    → nearby [ expr ] | ahead [ expr ] | random [ expr ] | smell
addop     → + | -
mulop     → * | / | mod

Sample Critter

species: simple
memsize: 8
defense: 1
offense: 1
size: 1
energy: 250
posture: 0

// Simple critter - moves around randomly and eats food
nearby[0] < -1 --> eat;
random[3] = 0 --> forward;
random[2] = 0 --> left;
1 = 1 --> wait;

Memory Layout

Index Name Description Read-only
0 memsize Memory array size Yes
1 defense Defense ability Yes
2 offense Attack ability Yes
3 size Critter size Yes
4 energy Current energy level Yes
5 pass Pass counter Yes
6 posture Posture value (0-99) No
7+ user User-defined values No

Hex Directions

  • 0: North
  • 1: Northeast
  • 2: Southeast
  • 3: South
  • 4: Southwest
  • 5: Northwest

Sensor Values

  • Empty hex: 0
  • Rock: -1
  • Food: -(food_amount + 1)
  • Critter: appearance value = size * 1000 + posture * 10 + direction

The direction in the appearance formula is relative to the observing critter's direction.

About

CS 2112 Critter World Simulation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages