A MVP of sorts

I have created a MVP with a number of AI behaviours. Whilst the game is not the finished article I would of liked, it does demonstrate the key components.

The main missing routine is the dragon health and movement, these are almost replicate of the monster-health and hero-consume routines for monster, but rather than dying, health would be decreased. As and when time allow I will revisit it, but wanted to get a submission in that at least shows a capability.

I have thoroughly enjoyed this module, and its not something I would of been able to do without this course. The level of understanding around gaming and AI, in particular NetLogo Agents, has been really good in progressing me from 0 to something playable and fun to work on.

Spawning cubes and Hero Health

Our hero now has health (albeit as a text value) and random spawning Gelatinous Cube’s!

Gelantious Cube monsters

The Gelantious Cube cannot be attacked with normal weapons, it just consumes them. The only way to defat a gelantious cube is that it will smear our hero, reducing his health ! As the cubes are randomly spwaning the are a dangerous collective ! The cubes, unlike the monsters, do not follow a path, they move randomly square to square, so our hero stands a chance of avoiding them by quick movements !

Snippets of the relevant cube creation, movement and consume are given below, as is the food and drink routines to increase health, please note this is almost pseudo code as they are not within their procedures.

;; if we encounter a cube, we cannot defeat it, only reduce our health by 5  
if any? cubes-here
  [ set health health - 5
    ask cubes-here [ die ] ]
;; cubes moving on a random-path
to move-cube ;; observer procedure for cube
  ask cubes
  [ ;if cube-eaten?
    fd 1
;; cube spawn routine, the coundown value reduces or increases the number of cubes being generated
to make-cube ;;
  ifelse next-cube-in = 0
  [ set next-cube-in 3 ]
  [ let cube-patch one-of patches with [treasures-grid? and
                                                not any? bonuses-here and
                                                not any? treasures-here]
    if cube-patch != nobody
    [ ask cube-patch
      [ sprout-cubes 1
        [ set shape "square"
          set heading 0
          set color one-of base-colors
          set value (random 10 + 1) * 100
          set cube-countdown random 200 + 50 ] ]
      set next-cube-in 10 + random 1 ] ]
;; food and drink
  ;; food
  if any? foods-here
  [ set health health + 9 
    ask foods-here [ die ]
  ;; drink
  if any? drinks-here
  [ set health health + 5
    ask drinks-here [ die ]

Level editor, bit of unix, VCS and SR & DR

Level Editor, Unix, VCS, SR & DR

Having played the initial walk thru, the placement of the keys makes the levels less challenging. In this video i adjust the positon of the keys, upon I discover the path to the output map is incorrect

I update the path to the map and show how this is done on teh command line, and then a little bit of version control, explaning the need for sustained resliency (local backups) and disaster recovery (remote backups) to ensure a project is not impacted by a individual failure.

Keys & Doors

Keys and Doors walkthru

In the video our hero can now pick up keys and walk thru doors.

This is accomplished by checking the tile ahead and wether our hero has the key. We also report in the GUI the ‘has-key’ value to show that the key is being consumed.

Firstly, in the ‘globals’ we create variables for storing the has-key value


And in the GUI create a reporter that returns that value

reporter for the has-red-key

We then need to know when our hero has encountered a key, consume it, then remove it from the dungeon.

to consume  ;;
  ;; red key
  if any? red-keys-here
  [ set has-red-key 1
  ask red-keys-here [ die ]

Then to be able to move around, and only go thru doors when the relevant keys are held

if [pcolor] of patch-ahead 1 = black
[ fd 1 ]
if [pcolor] of patch-ahead 1 = yellow and has-yellow-key = 1
[ fd 1 ]
if [pcolor] of patch-ahead 1 = green and has-yellow-key = 1
[ fd 1 ]
if [pcolor] of patch-ahead 1 = red and has-red-key = 1
[ fd 1
set level-over? true ]

Notice that when our hero can reach the red-door it is considered the end of the game, this logic will be further improved to only allow the red-door to be used once the dragon is also slayed.

First Test walk-thru

First walk thru

First walk thru of the Dragon game. I encounter some expected, and not so expected issues.

The ‘seek’ of the monsters is working, as is wall detection. The detection of food and drink is not there, but the procedures are not coded, so to be expected. When our hero encounters the first yellow door, he cannot pass, as he doesnt have the yellow key, as expected as the procedures are not there.

Best get coding !

Import to Game; Setup SR/DR

The first task on the game was to import the custom graphics for the dragon, food and keys.

Import graphics from level editor model
dragon, food and keys now present in game

When setting up the game for the first time, there were numerous errors, to be expected as game doesnt know ‘breeds’ for our ‘heros’ and ‘dragons’.

definitions in level-designer, need to be created in the game

And the new values I want to present in the GUI require code to complete them.

new reporters and chart require code to complete

At this point as I had completed a susbstanital amount of code locally, I commited all the code to version control software (VCS) – namely a local copy of Gitlab. This is setup to backup to my local Network Attached Storage, which in turn is also backed up to Amazon Web Services (AWS) S3 for both Sustained Resiliency (SR) and Disaster Recovery (DR). Not is only good practice to make regular commits to a VCS to track changes, it removes the failure of a single component (i.e. developer HDD) as potential source of project disruption.

VCS in action
VCS With most recent commits, server scripts ensure local and remote backups

Whilst there is no Continuous Integration / Continuous Delivery Pipeline, this would be something I will explore later, at least methods for code validate so pushes to ‘master’ will always contain working code.

Initial Map

Having completed enough to create an initial map i set about designing the level.

Initial Level Design

For the first part our hero will have no ‘Hero Mode’ activations, and will have to avoid the in-place monsters (which will seek) and the random spawn monsters (which will just move randomly).

The map design ensures our hero has enough to make risky moves that increase in skill/dexterity to complete, but are awarded higher scores. The gaps in the walls are intentionally off-set to the entrance making the hero cross the room, but if the treasure is to be avoided in the later stages, a dash across the room can be made, but at a lower score.

The food and drink is added, with more towards the of the level ready to combat the dragon. The dragon will have ‘health’ which will require several attacks in hero mode to win, also the special red key will need to be picked up to allow our hero to escape, having defeatd the dragon with all his treasures !

I made code updates in the designer to reflect the button modes and actions, i.e.

Place Treasure, not pill

and to create hero mode required adjust the shape and action within the code

to place-pellet
  ask patch (round mouse-xcor) (round mouse-ycor)
    ifelse pcolor != black
    [ user-message "You cannot place a treasure on top of a wall or a gate." ]
      if not any? turtles-here
        sprout-treasures 1
          set color yellow
          set powerup? false
          set shape "box"
        set treasures-grid? true
        set pcolor black

to hero-mode
  if any? treasures-on patch mouse-xcor mouse-ycor
    ask one-of treasures-on patch mouse-xcor mouse-ycor
      set powerup? not powerup?
      ifelse powerup?
      [ set shape "circle" ]
      [ set shape "pellet" ]
      while [ mouse-down? ] [ ] ;; wait until mouse button is released

The next step is within the game-code to add the additional code to update the UI, with values for each of the keys and also the dragon health, as well as the spawning of random monsters thru out the dungeon.

The Dragon !

Our ‘end level’ monster in the maze will the scary dragon. The Dragon will guard the final red key to exit the game. To defeat the dragon it will require maxium health and a power-up pill at the same time, so timing is critical – placement of these will ensure that it will be challenging, but not impossible.

Firstly, there was no dragon icon, so i created one. I found a knitting patten to copy as these are quite ‘blocky’ like the graphic editor.

Creating a button and associated code was an iteration of the key placements

breed [ dragons dragon ]
    if tool = "Place Dragon"
    [ place-dragon]
to place-dragon
  ifelse [pcolor] of patch round mouse-xcor mouse-ycor != black
  [ user-message "You must place the key on a corridor space, not a wall or a gate." ]
    ask dragons
    [ setxy (round mouse-xcor) (round mouse-ycor) ]

Whereby i was able to add the dragon to the designer

dragon added to editor and placed

Whilst the images currently look quite small, this will be corrected when the ‘setup’ adjust the world and patch sizes so they become more visable.

Food & Drink

Our Hero in game-play will have an energy bar, ranging from 0 to 100. When encountering monsters, energy will be reduced. Some designs of the map will require the hero to face the monsters and energy to be lessened, as there will be no power-up available to kill the monster.

With this placement of food and drink will have tactical positions so our hero can progress thruout the maze. For this the maze designer has food and drink buttons and associated breeds and procedures to support them. As no graphics for food or drink existed, these were created in the designer.

Because more than one food or drink is required, these are not created on ‘setup’ when the level is created, instead when the tool is selected and the mouse clicked, the patch is queried and when black, i.e. empty, a food or drink item is sprouted, i.e.

to place-food
  ask patch (round mouse-xcor) (round mouse-ycor)
    ifelse pcolor != black
    [ user-message "You cannot place food on top of other objects." ]
      if not any? turtles-here
        sprout-foods 1
          set color brown
          set shape "food"
        set treasures-grid? true
        set pcolor black

I can now create food and drink for our hero to battle our monsters and dragon !

tasty chicken wings and beer for our heroes health

Updating the Maze-Designer

Starting with the pac-man maze designer, i added new buttons and updated the existing code to use hero, monsters and treasure.

New Buttons Added, Doors, Keys, Food & Drink ; Hero and Monsters changed

Creating the code for the button calls on the function values supplied in the button i.e.

Set tool value based on the button
    ;; Green Door
    if tool = "Draw Green Door"
    [ draw-boundary green ]
    ;; Red Door
    if tool = "Draw Red Door"
    [ draw-boundary red ]
    if tool = "Draw Yellow Door"
    [ draw-boundary yellow ]

Which when applied creates the required doors

Different coloured doors which will only be accessible when holding the correct keys

The next step was to create the key. As there was no key graphic, the netlogo shap editor was used to create one.

green key creation

Then the code to support the creation and placement

breed       [ green-keys green-key ]
    create-green-keys 1
      set color green
      set shape "green key"
      setxy 10 10
to place-greenkey
  ifelse [pcolor] of patch round mouse-xcor mouse-ycor != black
  [ user-message "You must place the key on a corridor space, not a wall or a gate." ]
    ask green-keys
    [ setxy (round mouse-xcor) (round mouse-ycor) ]

When setting up the new level, the green key is now available to place.

doors and keys created

In the actual game i will now be able to have a register for ‘keys’ and when the hero encounters the key, take it and be able to pass the green door.