Skip to content

Commit df7dbec

Browse files
committed
Terminate added. The branch is created for qualification round judge.
1 parent a3d2c65 commit df7dbec

6 files changed

Lines changed: 39 additions & 17 deletions

File tree

Mithosis/Mithosis.iml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module type="WEB_MODULE" version="4">
2+
<module type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
@@ -8,8 +8,7 @@
88
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
1010
<orderEntry type="module" module-name="Common" />
11-
<orderEntry type="library" name="gson-2.3.1" level="project" />
1211
<orderEntry type="module" module-name="Server" />
13-
<orderEntry type="module" module-name="common" />
12+
<orderEntry type="library" name="gson-2.3.1" level="project" />
1413
</component>
1514
</module>

Mithosis/src/core/MitosisGameLogic.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import model.Event;
1212
import network.data.Message;
1313

14+
import javax.xml.bind.SchemaOutputResolver;
1415
import java.io.IOException;
1516
import java.util.*;
1617

@@ -19,7 +20,7 @@
1920
*/
2021
public class MitosisGameLogic implements GameLogic {
2122

22-
private final long GAME_LONG_TIME_TURN = 500;
23+
private final long GAME_LONG_TIME_TURN = 10;//TODO 500
2324

2425
private static final String RESOURCE_PATH_CLIENTS = "resources/mitosis/clients.conf";
2526

@@ -327,18 +328,14 @@ public void simulateEvents(Event[] terminalEvent, Event[] environmentEvent, Even
327328
}
328329
}
329330

330-
/*for (GameEvent event: gainResourceEvents) {
331-
Cell cell = null;
332-
for (Team team: mTeams) {
333-
if (team.getCellById(event.getGameObjectId()) != null)
334-
cell = team.getCellById(event.getGameObjectId());
331+
for(Team team : mTeams)
332+
{
333+
int score = 0;
334+
for (Cell cell: team.getCells()) {
335+
score += cell.getEnergy();
335336
}
336-
if (cell == null) continue;
337-
338-
// check if the location of the cell is of type resource
339-
if (map.at(cell.getPos().x, cell.getPos().y).equals(Block.TYPE_RESOURCE))
340-
cell.gainResource();
341-
}*/
337+
team.setScore(score);
338+
}
342339
ctx.incTurn();
343340
}
344341

@@ -496,4 +493,19 @@ public Event[] makeEnvironmentEvents() {
496493
public boolean isGameFinished() {
497494
return ctx.getTurn() >= GAME_LONG_TIME_TURN;
498495
}
496+
497+
@Override
498+
public void terminate()
499+
{
500+
if(mTeams.length > 0) {
501+
for (int i = 0; i < mTeams.length; i++) {
502+
if(i > 0)
503+
{
504+
System.out.print(", ");
505+
}
506+
System.out.print(mTeams[i].getScore());
507+
}
508+
System.out.println();
509+
}
510+
}
499511
}

Mithosis/src/core/model/Cell.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public boolean mitosis() {
101101
}
102102
int currentHeight = ctx.getMap().at(position).getHeight();
103103
int nextHeight = ctx.getMap().at(tPos).getHeight();
104-
if (nextHeight > currentHeight + 1) {
104+
if (nextHeight > currentHeight + 2) {
105105
continue;
106106
}
107107
if(ctx.getMap().at(tPos).isEmpty())
@@ -137,7 +137,7 @@ public boolean move(Position nextPos) {//TODO
137137
}
138138
int nextHeight = ctx.getMap().at(nextPos).getHeight();
139139
int currentHeight = ctx.getMap().at(position).getHeight();
140-
if(nextHeight > currentHeight +1)
140+
if(nextHeight > currentHeight +2)
141141
{
142142
return false;
143143
}

Mithosis/src/core/model/Team.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,12 @@ public void visitPosition(Position pos)
7474
{
7575
viewHistory[pos.getY()][pos.getX()] = ctx.getTurn();
7676
}
77+
78+
public int getScore() {
79+
return mScore;
80+
}
81+
82+
public void setScore(int mScore) {
83+
this.mScore = mScore;
84+
}
7785
}

Server/src/server/core/GameHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public void run() {
212212
mGameLogic.simulateEvents(terminalEvents, environmentEvents, clientEvents);
213213
mGameLogic.generateOutputs();
214214
if (mGameLogic.isGameFinished()) {
215+
mGameLogic.terminate();
215216
Message shutdown = new Message(Message.NAME_SHUTDOWN, new Object[] {});
216217
for (int i = 0; i < mClientsInfo.length; i++) {
217218
mClientNetwork.queue(i, shutdown);

Server/src/server/core/GameLogic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ public interface GameLogic {
6767
public Event[] makeEnvironmentEvents();
6868

6969
public boolean isGameFinished();
70+
71+
public void terminate();
7072
}

0 commit comments

Comments
 (0)