Up to Main Index                             Up to Journal for March, 2015

                     JOURNAL FOR FRIDAY 20TH MARCH, 2015
______________________________________________________________________________

SUBJECT: Quick Q&A
   DATE: Fri 20 Mar 21:13:04 GMT 2015

Since my last journal entry I've been asked the same two questions enough that
I thought I would answer them here.

                                    + + +

FIRST QUESTION: Why are you putting so much effort into WolfMUD-mini and
documenting it instead of actually working on WolfMUD?

The simple answer is that I am planning on making WolfMUD-mini the next
WolfMUD prototype. Therefore in a way I am working on WolfMUD. It took a lot
of time, effort, reasoning and soul searching to convince myself that the
current WolfMUD prototype was not working out well and to throw out years of
work. That was why I took a step back and created WolfMUD-mini to try new
ideas and approaches to doing things without any shackles. As it happens
WolfMUD-mini seems to have turned out particularly well in my opinion - but I
may be just a little biased ;)

                                    + + +

SECOND QUESTION: Why the fancy bit twiddling for calculating opposite exits?
What did the Java version do?

Okay, that's two questions and I'll answer them in reverse order. The Java
version had a second lookup array. In Go it could be define as:


  const (
    North byte = iota
    Northeast
    East
    Southeast
    South
    Southwest
    West
    Northwest
    Up
    Down
  )

  var oppositeDirection = [...]byte{
    North:     South,
    Northeast: Southwest,
    East:      West,
    Southeast: Northwest,
    South:     North,
    Southwest: Northeast,
    West:      East,
    Northwest: Southeast,
    Up:        Down,
    Down:      Up,
  }


Then you can easily get the index for the opposite direction using:

  oppositeDirection[direction]

For example oppositeDirection[North] returns South.

So why the switch to bit twiddling instead of a simple array lookup? Array
indexing and lookups are common, WolfMUD already contains plenty of such
examples. However, before reading my last journal entry how many readers do
you think had heard of bit twiddling? How many had used it?

You would probably find that flipping a bit in memory is more efficient than
an array lookup as well - I haven't benchmarked it myself and didn't choose
bit twiddling for performance reasons but more for its obscurity as a
technique that I seldom see many programmers using these days[1].

WolfMUD is not just about me taking ages to bang out game code for others to
run. People take WolfMUD and some will actually look at the code. Some will
hack on it for fun to produce a game for themselves and their friends. Some
will hack on the code as a fun way to learn coding. Some will just look at the
code to see how something is done. For all these people looking at the code I
try to provide good - sometimes humorous - comments and documentation. I try
to provide good examples of doing things or explaining why I have done
something differently. Now and again I will drop little gems that actually
make people think about the code or some function. To me the code is just as
important as the program. It is my hope that others will find pleasure in
reading, studying and learning from the WolfMUD sources.

--
Diddymus

  [1] I've also managed to get at least two informative journal entries out of
      it as well now :)


  Up to Main Index                             Up to Journal for March, 2015