forked from sat2707/aicups
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sat2707/master
Update
- Loading branch information
Showing
28 changed files
with
1,219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
```csharp | ||
// В стратегию приходит четыре массива | ||
List<Elevator> myElevators; | ||
List<Passenger> myPassengers; | ||
List<Elevator> enemyElevators; | ||
List<Passenger> enemyPassengers; | ||
// Для отладки в консоль используйте вызов | ||
this.log(Object object) | ||
// Каждый тик вызывается Strategy.onTick(List<Passenger>, List<Elevator>, List<Passenger>, List<Elevator>) | ||
// API для работы с пассажирами | ||
class Passenger { | ||
// Назначить пассажиру лифт | ||
public void SetElevator(Elevator elevator) {} | ||
// Проверяет, назначен ли лифт пассажиру | ||
public bool HasElevator() {} | ||
// Текущий этаж | ||
public int Floor; | ||
// Этаж, с которого едет пассажир | ||
public int FromFloor; | ||
// Этаж, на который едет пассажир | ||
public int DestFloor; | ||
// Состояние пассажира | ||
public int State; | ||
// Сколько времени осталось до ухода на лестницу | ||
public int TimeToAway; | ||
// Координаты пассажира | ||
public float Y; | ||
public float X; | ||
// Узнать к какому игроку привязан пассажир | ||
// Возвращаемое значение "FIRST_PLAYER", "SECOND_PLAYER" | ||
public String Type; | ||
// Вес пассажира | ||
public float Weight; | ||
} | ||
// API для работы с лифтами | ||
class Elevator { | ||
// Отправить лифт на указанный этаж, он доедет и выпустит пассажиров | ||
public void goToFloor(int floor) {} | ||
// Массив пассажиров, которых перевозит данный лифт | ||
public List<Passenger> Passengers; | ||
// Текущий этаж | ||
public int Floor; | ||
// Этаж, к которому лифт едет в данный момент | ||
public int NextFloor; | ||
// Сколько времени лифт простоял на этаже | ||
public int TimeOnFloor; | ||
// Координата лифта по Y | ||
public float Y; | ||
// Скорость движения в текущий момент | ||
public float Speed; | ||
// Какому игроку принадлежит | ||
// Возвращаемое значение "FIRST_PLAYER", "SECOND_PLAYER" | ||
public String Type; | ||
// Состояние Лифта | ||
public int State; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
```cpp | ||
// В стратегию приходят ссылки четыре массива | ||
std::vector<Elevator>& myElevators; | ||
std::vector<Passenger>& myPassengers; | ||
std::vector<Elevator>& enemyElevators; | ||
std::vector<Passenger>& enemyPassengers; | ||
// Для отладки в консоль используйте вызов this->log(T smth) | ||
// Допустимы типы: bool, int, short, long, float, double, char, QString, | ||
Passenger, Elevator | ||
// Каждый тик вызывается strategy->onTick(List<Passenger>, List<Elevator>, | ||
List<Passenger>, List<Elevator>) | ||
// API для работы с пассажирами | ||
class Passenger { | ||
public: | ||
// Текущий этаж | ||
int floor; | ||
// Этаж, с которого едет пассажир | ||
int from_floor; | ||
// Этаж, на который едет пассажир | ||
int dest_floor; | ||
// Координаты пассажира | ||
int x, y; | ||
// Сколько времени осталось до ухода на лестницу | ||
int time_to_away; | ||
// Состояние пассажира | ||
int state; | ||
// Узнать к какому игроку привязан пассажир | ||
// Возвращаемое значение "FIRST_PLAYER", "SECOND_PLAYER" | ||
QString type; | ||
public: | ||
// проверить, есть ли у пассажира лифт | ||
bool has_elevator() {} | ||
// назначить пассажиру лифт | ||
void set_elevator(const Elevator& elevator) {} | ||
}; | ||
// API для работы с лифтами | ||
class Elevator { | ||
public: | ||
// Текущий этаж | ||
int floor; | ||
// Этаж, к которому лифт едет в данный момент | ||
int next_floor; | ||
// Сколько времени лифт простоял на этаже | ||
int time_on_floor; | ||
// Координата лифта по Y | ||
double y; | ||
// Скорость движения в текущий момент | ||
double speed; | ||
// Какому игроку принадлежит | ||
// Возвращаемое значение "FIRST_PLAYER", "SECOND_PLAYER" | ||
QString type; | ||
// Состояние лифта | ||
int state; | ||
// Массив пассажиров, которых перевозит данный лифт | ||
std::vector<Passenger> passengers; | ||
public: | ||
// Отправить лифт на указанный этаж, он доедет и выпустит пассажиров | ||
void go_to_floor(int floor) {} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
To be done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"client/core/API" | ||
) | ||
|
||
type Strategy struct { | ||
API.BaseStrategy | ||
} | ||
|
||
// Вызывается при инициализации клиента | ||
func (s *Strategy) Init(){ | ||
|
||
} | ||
|
||
func (s *Strategy) OnTick(myPassengers []*API.Passenger, myElevators []*API.Elevator, | ||
enemyPassengers []*API.Passenger, enemyElevators []*API.Elevator) error { | ||
|
||
for i := 0; i < len(myElevators); i++ { | ||
elevator := myElevators[i] | ||
|
||
for j := 0; j < len(myPassengers); j++ { | ||
passenger := myPassengers[j] | ||
|
||
if passenger.State() < 5{ | ||
if elevator.State() != 1{ | ||
elevator.GoToFloor(passenger.FromFloor()) | ||
} | ||
if elevator.Floor() == passenger.Floor(){ | ||
passenger.SetElevator(elevator) | ||
} | ||
} | ||
} | ||
|
||
if len(elevator.Passengers()) > 0 && elevator.State() != 1{ | ||
elevator.GoToFloor(elevator.Passengers()[0].DestFloor()) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package API | ||
|
||
type API struct { | ||
mDebug *Debug | ||
mStrategy IBaseStrategy | ||
} | ||
|
||
func (a *API) parseState(state map[string]interface{}) ([]*Passenger, []*Elevator, []*Passenger, []*Elevator) { | ||
|
||
var myPassengers, enemyPassengers []*Passenger | ||
var myElevators, enemyElevators []*Elevator | ||
|
||
my_passengers, _ := state["my_passengers"] | ||
|
||
for _, passenger := range my_passengers.([]interface{}) { | ||
myPassengers = append(myPassengers, NewPassenger(passenger.(map[string]interface{}))) | ||
} | ||
|
||
enemy_passengers, _ := state["enemy_passengers"] | ||
|
||
for _, passenger := range enemy_passengers.([]interface{}) { | ||
enemyPassengers = append(enemyPassengers, NewPassenger(passenger.(map[string]interface{}))) | ||
} | ||
|
||
my_elevators, _ := state["my_elevators"] | ||
|
||
for _, elevator := range my_elevators.([]interface{}) { | ||
myElevators = append(myElevators, NewElevator(elevator.(map[string]interface{}))) | ||
} | ||
|
||
enemy_elevators, _ := state["enemy_elevators"] | ||
|
||
for _, elevator := range enemy_elevators.([]interface{}) { | ||
enemyElevators = append(enemyElevators, NewElevator(elevator.(map[string]interface{}))) | ||
} | ||
|
||
return myPassengers, myElevators, enemyPassengers, enemyElevators | ||
} | ||
|
||
func (a *API) Turn(state map[string]interface{}) []interface{}{ | ||
var messages []interface{} | ||
|
||
myPassengers, myElevators, enemyPassengers, enemyElevators := a.parseState(state) | ||
|
||
err := a.mStrategy.OnTick(myPassengers, myElevators, enemyPassengers, enemyElevators) | ||
|
||
if err != nil{ | ||
a.mDebug.Exception(err) | ||
} | ||
|
||
for i := 0; i < len(myPassengers); i++ { | ||
if m := myPassengers[i].Messages(); m != nil{ | ||
messages = append(messages, m...) | ||
} | ||
} | ||
|
||
for i := 0; i < len(myElevators); i++ { | ||
if m := myElevators[i].Messages(); m != nil{ | ||
messages = append(messages, m...) | ||
} | ||
} | ||
|
||
for i := 0; i < len(enemyPassengers); i++ { | ||
if m := enemyPassengers[i].Messages(); m != nil{ | ||
messages = append(messages, m...) | ||
} | ||
} | ||
|
||
for i := 0; i < len(enemyElevators); i++ { | ||
if m := enemyElevators[i].Messages(); m != nil{ | ||
messages = append(messages, m...) | ||
} | ||
} | ||
|
||
if m := a.mDebug.Messages(); m != nil{ | ||
messages = append(messages, m...) | ||
} | ||
|
||
return messages | ||
} | ||
|
||
func NewAPI(s IBaseStrategy) *API { | ||
a := &API{} | ||
a.mDebug = NewDebug() | ||
a.mStrategy = s | ||
a.mStrategy.Init() | ||
a.mStrategy.SetDebug(a.mDebug) | ||
|
||
return a | ||
} |
36 changes: 36 additions & 0 deletions
36
clients/go_client/client/src/client/core/API/BaseStrategy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package API | ||
|
||
type BaseStrategy struct { | ||
mDebug *Debug | ||
} | ||
|
||
type IBaseStrategy interface { | ||
Init() | ||
Debug() *Debug | ||
SetDebug(debug *Debug) | ||
Log(object interface{}) | ||
OnTick(myPassengers []*Passenger, myElevators []*Elevator, | ||
enemyPassengers []*Passenger, enemyElevators []*Elevator) error | ||
} | ||
|
||
func (s *BaseStrategy) Init() { | ||
|
||
} | ||
|
||
func (s *BaseStrategy) Debug() *Debug { | ||
return s.mDebug | ||
} | ||
|
||
func (s *BaseStrategy) SetDebug(debug *Debug) { | ||
s.mDebug = debug | ||
} | ||
|
||
func (s *BaseStrategy) Log(object interface{}) { | ||
s.mDebug.Log(object) | ||
} | ||
|
||
func (s *BaseStrategy) OnTick(myPassengers []*Passenger, myElevators []*Elevator, | ||
enemyPassengers []*Passenger, enemyElevators []*Elevator) error { | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package API | ||
|
||
import "fmt" | ||
|
||
type Debug struct { | ||
message | ||
} | ||
|
||
func (d *Debug) Log(object interface{}) { | ||
cmd := make(map[string]interface{}) | ||
cmd["text"] = fmt.Sprint(object) | ||
|
||
message := make(map[string]interface{}) | ||
message["command"] = "log" | ||
message["args"] = cmd | ||
|
||
d.mMessages = append(d.mMessages, message) | ||
} | ||
|
||
func (d *Debug) Exception(object interface{}) { | ||
cmd := make(map[string]interface{}) | ||
cmd["text"] = fmt.Sprint(object) | ||
|
||
message := make(map[string]interface{}) | ||
message["command"] = "exception" | ||
message["args"] = cmd | ||
|
||
d.mMessages = append(d.mMessages, message) | ||
} | ||
|
||
func NewDebug() *Debug { | ||
return &Debug{} | ||
} |
Oops, something went wrong.