Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #2

Merged
merged 9 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 56 additions & 41 deletions clients/c_sharp_client/client/core/api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ public Elevator (JObject elevator)
this.id = (int)elevator.GetValue("id");
this.y = (float)elevator.GetValue("y");

this.passengers = new List<Passenger>();
foreach (Object passennger in (JArray)elevator.GetValue("passengers"))
{
passengers.Add(new Passenger((JObject)passennger));
}
this.passengers = Helpers.ParsePassengers(elevator, "passengers");

this.state = (int)elevator.GetValue("state");
this.speed = (float)elevator.GetValue("speed");
Expand Down Expand Up @@ -128,7 +124,7 @@ public int Id
}

public int Elevator
{
{
get { return elevator; }
}

Expand Down Expand Up @@ -166,19 +162,19 @@ public int State
}

public int TimeToAway
{
{
get { return timeToAway; }
}

public String Type
{
public String Type
{
get { return type; }
}

public int Floor
public int Floor
{
get { return floor; }
}
}

public List<JObject> Messages
{
Expand All @@ -190,12 +186,18 @@ public List<JObject> Messages
public Passenger (JObject passenger)
{
id = (int)passenger.GetValue ("id");
try {
elevator = (int)passenger.GetValue ("elevator");

JToken jToken = passenger.GetValue ("elevator");

if (jToken != null && jToken.Type == JTokenType.Integer)
{
elevator = (int)jToken;
}
catch (System.ArgumentException) {
else
{
elevator = -1;
}

x = (float)passenger.GetValue("x");
y = (float)passenger.GetValue("y");
weight = (float)passenger.GetValue("weight");
Expand Down Expand Up @@ -244,7 +246,7 @@ public DebugClass()

public List<JObject> Messages
{
get
get
{
List<JObject> messages = this.messages;
this.messages = new List<JObject>();
Expand Down Expand Up @@ -282,10 +284,10 @@ public class api
baseStrategy strategy = null;


public api()
public api()
{
debug = new DebugClass ();
try
try
{
strategy = new client.strategy ();
strategy.Debug = debug;
Expand All @@ -297,38 +299,22 @@ public api()

private Tuple<List<Passenger>, List<Elevator>, List<Passenger>, List<Elevator>> parseState (JObject state)
{
List<Passenger> myPassengers = new List<Passenger>();
List<Elevator> myElevators = new List<Elevator>(3);
List<Passenger> myPassengers = Helpers.ParsePassengers(state, "my_passengers");
List<Elevator> myElevators = Helpers.ParseElevators(state, "my_elevators");

foreach (Object passennger in (JArray) state.GetValue("my_passengers")) {
myPassengers.Add (new Passenger ((JObject)passennger));
}
foreach (Object elevator in (JArray) state.GetValue("my_elevators")) {
myElevators.Add (new Elevator ((JObject)elevator));
}

List<Passenger> enemyPassengers = new List<Passenger>();
List<Elevator> enemyElevators = new List<Elevator>(3);

foreach (Object passennger in (JArray)state.GetValue("enemy_passengers"))
{
enemyPassengers.Add(new Passenger((JObject)passennger));
}
foreach (Object elevator in (JArray)state.GetValue("enemy_elevators"))
{
enemyElevators.Add(new Elevator((JObject)elevator));
}
List<Passenger> enemyPassengers = Helpers.ParsePassengers(state, "enemy_passengers");
List<Elevator> enemyElevators = Helpers.ParseElevators(state, "enemy_elevators");


return new Tuple<List<Passenger>, List<Elevator>, List<Passenger>, List<Elevator>>(myPassengers, myElevators, enemyPassengers, enemyElevators);
}

public JArray turn (JObject state) {
Tuple<List<Passenger>, List<Elevator>, List<Passenger>, List<Elevator>> quadruple = parseState(state);
try
try
{
this.strategy.onTick (quadruple.Item1, quadruple.Item2, quadruple.Item3, quadruple.Item4);
} catch (Exception e)
} catch (Exception e)
{
debug.exception (e);
}
Expand All @@ -352,7 +338,36 @@ public JArray turn (JObject state) {

return resultArray;
}

}
}

static class Helpers
{
public static List<Passenger> ParsePassengers(JObject jObject, string propertyName)
{
var values = (JArray)jObject.GetValue(propertyName);

List<Passenger> passengers = new List<Passenger>(values.Count);

foreach (JObject passenger in values)
{
passengers.Add(new Passenger(passenger));
}

return passengers;
}

public static List<Elevator> ParseElevators(JObject jObject, string propertyName)
{
var values = (JArray)jObject.GetValue(propertyName);

List<Elevator> elevators = new List<Elevator>(values.Count);

foreach (JObject elevator in values)
{
elevators.Add(new Elevator(elevator));
}

return elevators;
}
}
}
4 changes: 3 additions & 1 deletion clients/cpp11_client/client/core/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class Debug {
QString toString(double smth) { return QString::number(smth); }

QString toString(char smth) { return QString(smth); }
QString toString(const std::string &smth) { return QString::fromStdString(smth); }
QString toString(const char *smth) { return QString(smth); }
QString toString(QString smth) { return QString(smth); }
QString toString(Passenger& smth) { return "Passenger id=" + toString(smth.id); }
QString toString(Elevator& smth) { return "Elevator id=" + toString(smth.id); }
Expand Down Expand Up @@ -222,4 +224,4 @@ private slots:
void sendActions(QJsonArray);
};

#endif // API_H
#endif // API_H
2 changes: 1 addition & 1 deletion clients/go_client/client/src/client/core/API/API.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a *API) parseState(state map[string]interface{}) ([]*Passenger, []*Elevato
}

func (a *API) Turn(state map[string]interface{}) []interface{}{
var messages []interface{}
messages := []interface{}{}

myPassengers, myElevators, enemyPassengers, enemyElevators := a.parseState(state)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Passenger(passenger: JSONObject) : MessagesInterface{
private val messages = ArrayList<JSONObject>()
var x: Double = passenger["x"]?.toString()?.toDouble() ?: 0.0
var y: Double = passenger["y"]?.toString()?.toDouble() ?: 0.0
var weight: Double = passenger["weight"]?.toString()?.toDouble() ?: 0.0

override fun getMessages(): List<JSONObject> = messages

Expand Down
3 changes: 2 additions & 1 deletion clients/php7_client/client/core/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public function parse_state($state) {
$p->from_floor,
$p->dest_floor,
$p->type,
$p->floor
$p->floor,
$p->weight
);
}, $enemy_passengers);

Expand Down
4 changes: 2 additions & 2 deletions localrunner/visualizer/css/elevators.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
height: 70%;
}

#console {
.console {
background: #000;
color: #fff;
display: block;
overflow: auto;
}

#console span {
.console span {
word-wrap: break-word;
max-width: 430px;
display: inline-block;
Expand Down
17 changes: 13 additions & 4 deletions localrunner/visualizer/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
<html>
<head>

<meta charset="utf-8">
<link rel="stylesheet" href="css/icomoon.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/elevators.css">
<link rel="stylesheet" href="css/elevators.css">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br/>
<div class="preloader">
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-3">
<div id="left-console" class="console">
</div>
</div>
<div class="col-xs-6">
<div class="mechanic-screen">
<div class="world-screen">
<div id="world-wrap"></div>
</div>
</div>
</div>
<div class="col-xs-3">
<div id="right-console" class="console">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
Expand Down Expand Up @@ -56,7 +65,7 @@
</div>
<script src="game.js"></script>
<script>
PATH_IMG = 'img/';
PATH_IMG = 'http://aicups.ru/static/contest/elevators_multiplayer/img/';
</script>
<script data-main="js/main" src="js/libs/require-2.2.0.js"></script>

Expand Down
12 changes: 0 additions & 12 deletions localrunner/visualizer/js/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,7 @@ define([], function () {
floorXShift: -5,
floorYShift: -5
},
OPTIONS_DOOR: {
width: 31,
height: 56.8,
openDoorPositionX: 7,
closeDoorPositionX: 456,
OPEN_ANIMATION: {
path: 'motion/door/70x126/door{}.png',
count: 11,
speed: 0.5
}
},
IMG: {
world: '1/scene.png',
texture: '1/pattern.png',
floor: '1/floor.png'
},
Expand Down
18 changes: 5 additions & 13 deletions localrunner/visualizer/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ define(['conf', 'underscore'], function (conf, _) {
}
}

function getVisio(url) {
return new Promise(function (resolve, reject) {
$.get(url).done(function (result) {
result = JSON.parse(result);
resolve(result);
});
})
}

function registerEvents(init) {
var runButton = $('.js-run');
var pauseButton = $('.js-pause');
Expand All @@ -31,9 +22,8 @@ define(['conf', 'underscore'], function (conf, _) {
var x4Button = $('.js-x4');
var range = $('.range');
var currentSpan = $('.js-score-time-user');
// var world = null;
// var renderer = null;

var leftConsole = $('#left-console');
var rightConsole = $('#right-console');

var visio = data;
var config = visio.config;
Expand All @@ -45,13 +35,15 @@ define(['conf', 'underscore'], function (conf, _) {
conf.HEIGHT = (config.FLOORS_COUNT + 1) * conf.FLOOR_HEIGHT;

var renderer = new PIXI.autoDetectRenderer(conf.WIDTH, conf.HEIGHT);
var world = init.initWorld(visio.game_data, config, renderer, scoreAndTimeSetter(currentSpan, visio.players), range);
var world = init.initWorld(visio.game_data, config, renderer, scoreAndTimeSetter(currentSpan, visio.players), range, leftConsole, rightConsole);

range.val(0);
range.prop("disabled", false);
range.removeClass('btn_disabled');

ww.html(renderer.view);
leftConsole.height(ww.height());
rightConsole.height(ww.height());
$('.preloader').fadeOut();


Expand Down
Loading