Skip to content

Commit 2f41894

Browse files
Merge pull request #5 from ThomaHakkers/naval-robocode-workspace2
Naval robocode workspace2
2 parents 8fe6a77 + a8d9dba commit 2f41894

15 files changed

Lines changed: 194 additions & 33 deletions

File tree

naval-robocode-versions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Naval Robocode Version 0.9.3 (28-Feb-2015)
2+
3+
### Bug fixes
4+
* Now able to use naval-robocode.bat to start Naval Robocode
5+
* Fixed a few UnitTests that fell short due to a few missing classes
6+
17
## Naval Robocode Version 0.9.2 (24-Feb-2015)
28

39
### Changes

robocode.battle/src/main/java/net/sf/robocode/battle/peer/RobotPeer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public RobotPeer(Battle battle, IHostManager hostManager, RobotSpecification rob
186186
* Empty constructor for RobotPeer
187187
*/
188188
public RobotPeer(){
189-
super();
190189
this.battle = null;
191190
this.robotSpecification = null;
192191

robocode.battle/src/main/java/net/sf/robocode/battle/peer/ShipPeer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ public ShipPeer(Battle battle, IHostManager hostManager, RobotSpecification robo
8686

8787
}
8888

89-
// /**
90-
// * Is here to do a few tests. See TestWallCollision
91-
// */
92-
// public ShipPeer(){
93-
// super();
94-
// initComponents();
95-
// boundingRectangle = new BoundingRectangle(0,0,NavalRules.WIDTH, NavalRules.HEIGHT);
96-
// statistics = new ShipStatistics(this, battle.getRobotsCount());
97-
// }
98-
//
89+
/**
90+
* Is here to do a few tests. See TestWallCollision
91+
*/
92+
public ShipPeer(){
93+
super();
94+
initComponents();
95+
boundingRectangle = new BoundingRectangle(0,0,NavalRules.WIDTH, NavalRules.HEIGHT);
96+
statistics = new ShipStatistics(this, 2); //always 2
97+
}
98+
9999
/**
100100
* Returns the "BoundingBox" of the Ship.
101101
* This is in fact not an actual BoundingBox. It's just a box that has the same size as the Ship.
@@ -305,7 +305,7 @@ public void checkWallCollision() {
305305
angle = Utils.normalRelativeAngle(-bodyHeading);
306306
}
307307
//Top Wall Forward
308-
if (getY() <= OFFSET_BASED_ON_HEADING_Y_FORWARD) {
308+
if (getY() <= OFFSET_BASED_ON_HEADING_Y_FORWARD) {
309309
hitWall = true;
310310
angle = Utils.normalRelativeAngle(Math.PI - bodyHeading);
311311
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@REM
2+
@REM Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
3+
@REM All rights reserved. This program and the accompanying materials
4+
@REM are made available under the terms of the Eclipse Public License v1.0
5+
@REM which accompanies this distribution, and is available at
6+
@REM http://robocode.sourceforge.net/license/epl-v10.html
7+
@REM
8+
9+
java -Xmx512M -cp libs/robocode.jar robocode.NavalRobocode %*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
4+
# All rights reserved. This program and the accompanying materials
5+
# are made available under the terms of the Eclipse Public License v1.0
6+
# which accompanies this distribution, and is available at
7+
# http://robocode.sourceforge.net/license/epl-v10.html
8+
#
9+
10+
pwd=`pwd`
11+
cd "${0%/*}"
12+
java -Xmx512M -cp libs/robocode.jar robocode.Robocode $*
13+
cd "${pwd}"

robocode.core/src/main/java/net/sf/robocode/core/Module.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ public void afterLoaded(List<IModule> allModules) {
3838
RbSerializer.register(ExecResults.class, RbSerializer.ExecResults_TYPE);
3939
RbSerializer.register(BulletStatus.class, RbSerializer.BulletStatus_TYPE);
4040
RbSerializer.register(RobotStatics.class, RbSerializer.RobotStatics_TYPE);
41+
// Naval \\
42+
RbSerializer.register(ComponentCommands.class, RbSerializer.ComponentsCommand_TYPE);
4143
}
4244
}

robocode.core/src/main/java/net/sf/robocode/peer/ExecCommands.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,24 @@ public int sizeOf(RbSerializer serializer, Object object) {
386386
}
387387
size += 1;
388388

389-
// Custom
390-
size += 6 * RbSerializer.SIZEOF_DOUBLE;
391-
size += 2 * obj.getMaxComponents() * RbSerializer.SIZEOF_DOUBLE;
392-
size += obj.getMaxComponents() * RbSerializer.SIZEOF_BOOL;
389+
// Naval
390+
// private List<ComponentCommands> componentCommands = new ArrayList<ComponentCommands>(getMaxComponents());
391+
// private List<MineCommand> mines = new ArrayList<MineCommand>();
392+
// size += 6 * RbSerializer.SIZEOF_DOUBLE;
393+
// size += 2 * obj.getMaxComponents() * RbSerializer.SIZEOF_DOUBLE;
394+
// size += obj.getMaxComponents() * RbSerializer.SIZEOF_BOOL;
395+
396+
// Mines
397+
for (MineCommand mine : obj.mines) {
398+
size += serializer.sizeOf(RbSerializer.MineCommand_TYPE, mine);
399+
}
400+
size += 1;
401+
402+
// properties
403+
for (ComponentCommands c : obj.componentCommands) {
404+
size += serializer.sizeOf(RbSerializer.ComponentsCommand_TYPE, c);
405+
}
406+
size += 1;
393407

394408
return size;
395409
}
@@ -437,14 +451,16 @@ public void serialize(RbSerializer serializer, ByteBuffer buffer, Object object)
437451
serializer.serialize(buffer, RbSerializer.DebugProperty_TYPE, prop);
438452
}
439453
buffer.put(RbSerializer.TERMINATOR_TYPE);
454+
455+
// Custom - Naval Lists
440456
for (MineCommand mine : obj.mines) {
441457
serializer.serialize(buffer, RbSerializer.MineCommand_TYPE, mine);
442458
}
443459
buffer.put(RbSerializer.TERMINATOR_TYPE);
444-
// Custom - Lists
445460
for (ComponentCommands c : obj.componentCommands) {
446461
serializer.serialize(buffer, RbSerializer.ComponentsCommand_TYPE, c);
447462
}
463+
buffer.put(RbSerializer.TERMINATOR_TYPE);
448464
}
449465

450466
public Object deserialize(RbSerializer serializer, ByteBuffer buffer) {
@@ -500,20 +516,27 @@ public Object deserialize(RbSerializer serializer, ByteBuffer buffer) {
500516
}
501517
item = serializer.deserializeAny(buffer);
502518
}
503-
519+
// Custom - Naval Lists
520+
item = serializer.deserializeAny(buffer);
504521
while (item != null) {
505522
if (item instanceof MineCommand) {
506523
res.mines.add((MineCommand) item);
507524
}
508525
item = serializer.deserializeAny(buffer);
509526
}
510-
511-
// Custom - Lists
512-
int maxCapacity = res.getMaxComponents();
513-
for (int i = 0; i < maxCapacity; i++) {
514-
res.componentCommands.add(i, (ComponentCommands)serializer.deserializeAny(buffer));
527+
item = serializer.deserializeAny(buffer);
528+
while (item != null) {
529+
if (item instanceof ComponentCommands) {
530+
res.componentCommands.add((ComponentCommands) item);
531+
}
532+
item = serializer.deserializeAny(buffer);
515533
}
516534

535+
// int maxCapacity = res.getMaxComponents();
536+
// for (int i = 0; i < maxCapacity; i++) {
537+
// res.componentCommands.add(i, (ComponentCommands)serializer.deserializeAny(buffer));
538+
// }
539+
517540
return res;
518541
}
519542
}

robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class EventManager implements IEventManager {
4343
private Event currentTopEvent;
4444
private int currentTopEventPriority;
4545
private ScannedRobotEvent dummyScannedRobotEvent;
46+
private ScannedShipEvent dummyScannedShipEvent;
4647
private Map<String, Event> eventNames;
4748

4849
private IBasicRobot robot;
@@ -256,6 +257,21 @@ public List<ScannedRobotEvent> getScannedRobotEvents() {
256257
}
257258
return events;
258259
}
260+
261+
/**
262+
* Returns a list containing all ScannedRobotEvents currently in the robot's queue.
263+
*/
264+
public List<ScannedShipEvent> getScannedRobotEvents2() {
265+
List<ScannedShipEvent> events = new ArrayList<ScannedShipEvent>();
266+
synchronized (eventQueue) {
267+
for (Event e : eventQueue) {
268+
if (e instanceof ScannedShipEvent) {
269+
events.add((ScannedShipEvent) e);
270+
}
271+
}
272+
}
273+
return events;
274+
}
259275

260276
/**
261277
* Returns a list containing all MessageEvents currently in the robot's queue.
@@ -324,6 +340,13 @@ public void setRobot(IBasicRobot robot) {
324340
public int getScannedRobotEventPriority() {
325341
return dummyScannedRobotEvent.getPriority();
326342
}
343+
344+
/**
345+
* Returns the priority of a ScannedShipEvent.
346+
*/
347+
public int getScannedShipEventPriority() {
348+
return dummyScannedShipEvent.getPriority();
349+
}
327350

328351
/**
329352
* Returns the current time/turn of the battle round.
@@ -512,6 +535,7 @@ public void setEventPriority(String eventClass, int priority) {
512535
private void registerEventNames() {
513536
eventNames = new HashMap<String, Event>();
514537
dummyScannedRobotEvent = new ScannedRobotEvent(null, 0, 0, 0, 0, 0, false);
538+
dummyScannedShipEvent= new ScannedShipEvent(null, 0, 0, 0, 0, 0, 0, 0);
515539
registerEventNames(new BattleEndedEvent(false, null));
516540
registerEventNames(new BulletHitBulletEvent(null, null));
517541
registerEventNames(new BulletHitEvent(null, 0, null));
@@ -536,9 +560,15 @@ private void registerEventNames() {
536560
registerEventNames(new RobotDeathEvent(null));
537561
registerEventNames(new RoundEndedEvent(0, 0, 0));
538562
registerEventNames(dummyScannedRobotEvent);
563+
registerEventNames(dummyScannedShipEvent);
539564
registerEventNames(new SkippedTurnEvent(0));
540565
registerEventNames(new StatusEvent(null));
541566
registerEventNames(new WinEvent());
567+
568+
//Mines
569+
registerEventNames(new MineHitMineEvent(null, null));
570+
registerEventNames(new MineHitEvent("", 0, null));
571+
registerEventNames(new HitByMineEvent(null));
542572

543573
// same as any line above but for custom event
544574
final DummyCustomEvent customEvent = new DummyCustomEvent();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tested.ships;
2+
3+
4+
import robocode.HitWallEvent;
5+
import robocode.Ship;
6+
import robocode.naval.NavalRules;
7+
8+
public class IndependentComponentShip extends Ship{
9+
int direction = 1;
10+
int i = 0;
11+
@Override
12+
public void run() {
13+
//Make sure every component moves independently
14+
setAdjustComponentForShipTurn(NavalRules.IDX_CENTRAL_RADAR, true);
15+
setAdjustComponentForShipTurn(NavalRules.IDX_WEAPON_FRONT, true);
16+
setAdjustComponentForShipTurn(NavalRules.IDX_WEAPON_BACK, true);
17+
setTurnRightRadians(Double.POSITIVE_INFINITY);
18+
19+
while (true) {
20+
System.out.print(i + ": " + getRadarHeadingDegrees());
21+
setTurnRightDegrees(90);
22+
setAhead(50*direction);
23+
execute();
24+
}
25+
}
26+
27+
@Override
28+
public void onHitWall(HitWallEvent e){
29+
direction *= -1;
30+
}
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package tested.ships;
2+
3+
import robocode.Ship;
4+
5+
public class MineShip extends Ship{
6+
public void run(){
7+
System.out.println("Mine placed: " + placeMine(15));
8+
}
9+
}

0 commit comments

Comments
 (0)