Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10323 for trunk


Ignore:
Timestamp:
01/10/14 09:03:14 (11 years ago)
Author:
gkronber
Message:

#2133 changed calculation of position for lawn mower when 'frogging'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Interpreter.cs

    r9456 r10323  
    5454      lawn[mowerState.Position.Item1, mowerState.Position.Item2] = true;
    5555      EvaluateLawnMowerProgram(tree.Root, mowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray());
    56 
    5756      return lawn;
    5857    }
     
    115114      } else if (node.Symbol is Frog) {
    116115        var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    117 
    118         uint newRow = (uint)((mowerState.Position.Item1 + lawn.GetLength(0) + p.Item1 % lawn.GetLength(0)) % lawn.GetLength(0));
    119         uint newCol = (uint)((mowerState.Position.Item2 + lawn.GetLength(1) + p.Item2 % lawn.GetLength(1)) % lawn.GetLength(1));
     116        int x = p.Item1;
     117        int y = p.Item2;
     118        while (x < 0) x += lawn.GetLength(0);
     119        while (y < 0) y += lawn.GetLength(1);
     120        var newRow = (uint)((mowerState.Position.Item1 + x) % lawn.GetLength(0));
     121        var newCol = (uint)((mowerState.Position.Item2 + y) % lawn.GetLength(1));
    120122        mowerState.Position = new Tuple<uint, uint>(newRow, newCol);
    121123        mowerState.Energy = mowerState.Energy - 1;
     
    130132                                  select adf).Single();
    131133        // clone the function definition because we are replacing the argument nodes
    132         functionDefinition = (DefunTreeNode) functionDefinition.Clone();
     134        functionDefinition = (DefunTreeNode)functionDefinition.Clone();
    133135        // find the argument tree nodes and their parents in the original function definition
    134136        // toList is necessary to prevent that newly inserted branches are iterated
Note: See TracChangeset for help on using the changeset viewer.