Bah humbug

When Mood Music
2012-04-16 17:43:00 confused Save The Day – Diss-cuss

Wierdness: so long as I start a new game each time, the game plays out as it should. However, if I recall a saved game from disk, the creatures appear not to battle and are effectively immortal.

This may or may not be connected with the moveAllCreatures() method in Swamp.class appearing to call moveCreature() in Creature.class at least twice per Creature.

If it were always twice, I’d be a little less confused.

Statistics

When Mood Music
2012-04-16 14:25:00 ground state, i.e. prevaricating Robber Rock – Yabby U

My lecturer tells me ‘All debugging code should be removed. The only exception is when a program can be run in debug mode as per SD1 coursework.’

I’ve saved a copy with the extra methods and commented-out pieces to track events elsewhere, then looked at what’s left after removing these undesirables.

 

Version lines ‘words’ characters characters that are spaces
complete code
340
1834
15,021
2654
comment lines removed,
i.e. just code lines
217
986
8345
1260
%
64
54
55
47
Hence comment lines
123
848
6676
1394
%
36
46
45
43
inline comments (e.g. //end method) removed,
i.e. pure code
217
873
7517
1148
%
64
45
50
43

So I’ve written 217 lines of code for this class of which around 50% is substantive – the rest is spaces and comments to allow humans to read it.

Programming coursework entries

When Mood Music
2012-04-16 12:29:00 sore Rino’s Prayer – Leftfield

With thanks to ggreig for alerting me to this…

It turns out I was using an image format that’s unsuitable for most browsers, so you may have been seeing ‘broken-link’ images or bank spaces instead of screenshots.

I’ve now converted the screenshots to PNG format – this seems to work in all the browsers I have for MacOSX Lion, Ubuntu Linux and Windows XP.

Some more progress

When Mood Music
2012-04-15 22:31:00 content Repeat (Stars And Stripes) – Manic Street Preachers

I’ve got further today than I dared hope: getting the battle code roughly working was my minimum aim. It’s working OK and so I’ve been able to do more. Here’s a checklist:

The remaining tasks are

  • ensuring the ogre doesn’t start at (0,0) That took 3 extra lines, one of which was merely ‘}’
  • reducing the number of times the map is drawn Now just at the very beginning of the game (to show the solitary ogre), then once per turn, then once at the end of the game.
  • creating an interface which is completely independent of the game
  • enabling saving of the current game and later restarting it
  • writing comprehensive JUnit tests for each method (excluding the constructors) defined on the class Swamp
  • writing a report on
    • how I created the swamp
    • where and why I used polymorphic programming
    • my programming style (i.e. showing where and why you have used things like interfaces, enumerator, exceptions etc) There are none of these in the current code, although I suspect I should use an enumerator for the types of enemy.
    • how my swamp is extensible
    • any problems encountered during the coding of my game. Hence these blog entries!

Success!

When Mood Music
2012-04-15 19:24:00 pleased Agog in the Ether – Ozric Tentacles

The basic game does what it should:

Swampy bloodbath!

  1. It creates a swamp creating an ogre in a random position.
  2. An enemy may enter.
  3. All creatures in the swamp move to a proximate location.
  4. Steps 2 and 3 repeat …

    until one or more enemies enter the ogre’s current location.

    • If there is only enemy in the ogre’s current location, it is killed and this happy event is reported.
      Then steps 2 and 3 begin to be repeated.
    • If there are two or more enemies in the creature’s location, the ogre is killed and this sad event is reported.

 

The remaining tasks are

  • ensuring the ogre doesn’t start at (0,0)
  • reducing the number of times the map is drawn
  • creating an interface which is completely independent of the game
  • enabling saving of the current game and later restarting it
  • writing comprehensive JUnit tests for each method (excluding the constructors) defined on the class Swamp
  • writing a report on
    • how I created the swamp
    • where and why I used polymorphic programming
    • my programming style (i.e. showing where and why you have used things like interfaces, enumerator, exceptions etc) There are none of these in the current code, although I suspect I should use an enumerator for the types of enemy.
    • how my swamp is extensible
    • any problems encountered during the coding of my game. Hence these blog entries!

I need to demonstrate my program and submit my report next Tuesday, so I better crack on.

One refinement I could make is to not use both type (‘ogre’ or ‘enemy’) and subtype of enemy (‘donkey’, ‘snake’ and ‘parrot’). I think these could be collapsed into just one type. Then I’d only need one non-abstract class of creature. But this would remove all vestiges of polymorphic programming from my code…

Bah! again

When Mood Music
2012-04-15 17:54:00 bitchy Again and Again – Phil Kieran

I think I have it: it seems I was still trying to take a step while examining the list of creatures in a different place. Back to the full game to find out.

This is not the bug you’re looking for

When Mood Music
2012-04-15 17:30:00 confused Wombo Lombo – Angélique Kidjo

I think the bug I’m currently trying to squash is in the ‘remove’ method called from battle(). I’ve traced it by putting single lines of code to display a number after each step. So far, the numbers appear in order.

The remove method works by finding the position (index) in the ArrayList of the creature to be removed, then removing the creature at that index. (You can’t do simply ‘remove this type of creature’. The remove step needs two parts so that you don’t try to remove something from a collection that’s currently being examined – that way lies crash city.)

I was puzzled because the index of the creature to be removed was constantly ‘1’, even though the first creature to be added was an ogre – and the remove code will only work if the creature to be removed is an enemy.

I’d forgotten that computing numbers start at ‘zero’. Bah!

Back to bug-squashing…

getting there – maybe

 

When Mood Music
2012-04-15 14:51:00 disappointed Will The Circle Be Unbroken – Hayseed Dixie

I’ve started assembling the actual game – a separate program which calls methods from the Swamp class as needed. It doesn’t quite work yet – the battle section crashes. One reason for this was that I wasn’t checking the current enemy’s type – so the ogre was killing itself!

Having cured this – suicidal ogres are not allowed – and temporarily removed the ‘battle’ section from the game code, the following occurred.:

A swamp is created and an ogre is added.
Turn 1. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 2. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 3. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 4. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 5. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 6. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 7. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 8. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 9.No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 10. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 11. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 12. An enemy parrot arrives.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 13. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 14. An enemy donkey arrives.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 15. Another enemy parrot arrives.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 16. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 17. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 18. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 19. Another enemy donkey arrives.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 20. No enemy has been added.
All creatures move.
A battle should occur here, resulting in the parrot at (1,1) being removed to leave just the ogre at those coordinates.
Turn 21. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are.
Turn 22. Yet another enemy parrot arrives.
All creatures move.
At this point, a battle should occur at (1,1), resulting in the ogre being killed by 2 parrots. But this code isn’t yet called, so the ogre lives on.
Turn 23. No enemy has been added.
All creatures move.
No battle occurs so everyone stays where they are……….

 

This is where the extra methods will be useful. I can create a swamp with creatures where I choose and see whether the battle proceeds as it should.