robocup-atan / atan

Robocup 2D Soccer Server Java Interface
MIT License
20 stars 6 forks source link

Ambiguous see commands are discarded #36

Open devgg opened 8 years ago

devgg commented 8 years ago
(see ObjName Distance Direction DistChng DirChng BodyDir HeadDir)

ObjName ::= (p ”Teamname” UniformNumber goalie)

When the teamname is specified (e.g. (p team1)) the message gets passed on. But when the player is to far away to see the teamname the message just gets discarded.

I.e. some messages get thrown away by the parser even if they could be useful to the programmer.

devgg commented 8 years ago

On second thought this might not be intentional i.e. might be a bug.

hadesrofl commented 8 years ago

Hey, @devgg . Thanks to your Issue we got to the same conclusion. I fixed it like this in the parser:

ObjName objName() :
  {Token name; Token num; ObjName objName=null;} {
    <P>[[<SEP>]objName=objNamePlayer()] {
      if (objName==null) return new ObjNameUnknown(UnknownObject.PLAYER);
      else return objName;
    } |
    <B> {
      return new ObjNameBall();
    } |
    <FLAG>[<SEP>objName=objNameFlag()] {
      if (objName==null) return new ObjNameUnknown(UnknownObject.FLAG);
      else return objName;
    } |
    <L><SEP>objName=objNameLine() {
      return objName;
    } |
    <GOAL>[<SEP>objName=objNameFlagGoal()] {
      if (objName==null) return new ObjNameUnknown(UnknownObject.GOAL);
      else return objName;
    }
  }

As mentioned in the manual of the server with unknown name B, G, F or P is sent via the server. As Ball is not important if a player can see it's "name" I just distinguish between Goals, Flags and Players. Therefore I changed the returned ObjNameNull to my own ObjNameUnknown. Like this:

package com.github.robocup_atan.atan.parser.objects;

//~--- non-JDK imports --------------------------------------------------------

import java.rmi.activation.UnknownObjectException;

import com.github.robocup_atan.atan.model.ControllerCoach;
import com.github.robocup_atan.atan.model.ControllerPlayer;
import com.github.robocup_atan.atan.model.ControllerTrainer;
import com.github.robocup_atan.atan.model.enums.UnknownObject;

/**
 * A unknown Object. If the name of the specific object is unknown it is stated
 * as G, F or P for Goal, Flag or Player.
 *
 * @author Atan modified by @author René Kremer
 */
public class ObjNameUnknown implements ObjName {
    /**
     * Object Type as stated in the manual (GOAL, FLAG or PLAYER)
     */
    private UnknownObject objType;

    /**
     * Constructor
     * 
     * @param type
     *            is the UnknownObject Type given via see command
     */
    public ObjNameUnknown(UnknownObject type) {
        if (type != null) {
            switch (type) {
            case GOAL:
                this.objType = UnknownObject.GOAL;
                break;
            case FLAG:
                this.objType = UnknownObject.FLAG;
                break;
            case PLAYER:
                this.objType = UnknownObject.PLAYER;
                break;
            default:
                this.objType = null;
            }
        } else {
            this.objType = null;
        }

    }

    /** {@inheritDoc} */
    @Override
    public void infoSeeFromEast(ControllerPlayer c, double distance,
            double direction, double distChange, double dirChange,
            double bodyFacingDirection, double headFacingDirection) {
        c.infoSeeUnknownObject(this.objType, distance, direction, distChange,
                dirChange, bodyFacingDirection, headFacingDirection);
    }

    /** {@inheritDoc} */
    @Override
    public void infoSeeFromWest(ControllerPlayer c, double distance,
            double direction, double distChange, double dirChange,
            double bodyFacingDirection, double headFacingDirection) {
        c.infoSeeUnknownObject(this.objType, distance, direction, distChange,
                dirChange, bodyFacingDirection, headFacingDirection);
    }

    /** {@inheritDoc} */
    @Override
    public void infoSeeFromEast(ControllerCoach c, double x, double y,
            double deltaX, double deltaY, double bodyAngle, double neckAngle) {
        c.infoSeeUnknownObject(this.objType, x, y, deltaX,
                deltaY, bodyAngle, neckAngle);
    }

    /** {@inheritDoc} */
    @Override
    public void infoSeeFromWest(ControllerCoach c, double x, double y,
            double deltaX, double deltaY, double bodyAngle, double neckAngle) {
        c.infoSeeUnknownObject(this.objType, x, y, deltaX,
                deltaY, bodyAngle, neckAngle);
    }

    /** {@inheritDoc} */
    @Override
    public void infoSee(ControllerTrainer c) {
    }
}

UnknownObject is a Enum containing the Values for P, F and G. Nothing fancy.

Well you need to adjust your ControllerCoach & ControllerPlayer to have a method called infoSeeUnknownObject, but that's just some minor changes.

Hope that helps you. I am working on Atan 0.44 because we had some problems with 0.45 and reworked some Commits from the Atan guys, so that we can work with the framework for our University Project.

verbitan commented 8 years ago

Thanks guys for raising this, I'll look to pull these changes into Atan when I've got some time (I'm not actively developing Atan at the moment).

If you wouldn't mind raising a pull request, I'll merge the changes in.

hadesrofl commented 8 years ago

I don't know if that's what you want. I am working on your version 0.44 because 0.45 had some errors we didn't found the reason for. So I don't know if you want to merge some code for version 0.44 in your 0.45 code. However I can provide you with the modified 0.44 code if you like. We fixed some parsing errors like missing referee messages or playmodes. We also implemented a new dash allowing to give it a direction in addition to the dash power and receiving the current cycle of the game. So it's something between a fix and updating missing features.

We are using atan for an university project, which will end in early July.

verbitan commented 8 years ago

Sorry for the incredibly late reply...

I can't see an issue with submitting a pull request even though you've made changes against an earlier version, they should resolve nicely. Either way, if you submit the request, I'll make any changes if need be and merge them in.

hadesrofl commented 8 years ago

You need to check if you can use the changes as you made some major ones with version 0.45, but feel free to use what you need as Version 0.44 worked in this modified version for our team using server version 15.xx (dunno like 15.3?).