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 #3 from sat2707/master
Update
- Loading branch information
Showing
23 changed files
with
18,329 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "strategy.h" | ||
#include <iostream> | ||
|
||
std::ostream & operator << (std::ostream &s, const Elevator &e) | ||
{ | ||
s << "Elevator(id=" << e.id << ")"; | ||
return s; | ||
} | ||
|
||
std::ostream & operator << (std::ostream &s, const Passenger &p) | ||
{ | ||
s << "Passenger(id=" << p.id << ")"; | ||
return s; | ||
} | ||
|
||
void Strategy::on_tick(const std::vector<Elevator>& myElevators, | ||
const std::vector<Passenger>& myPassengers, | ||
const std::vector<Elevator>& enemyElevators, | ||
const std::vector<Passenger>& enemyPassengers) | ||
{ | ||
for (auto& elevator : myElevators) | ||
{ | ||
for (auto& passenger : myPassengers) | ||
{ | ||
if (passenger.state < 5) | ||
{ | ||
if (elevator.state != 1) | ||
{ | ||
elevator.go_to_floor(passenger.from_floor); | ||
} | ||
if (elevator.floor == passenger.from_floor) | ||
{ | ||
passenger.set_elevator(elevator); | ||
} | ||
} | ||
} | ||
if(elevator.passengers.size() > 0 && elevator.state != 1) | ||
{ | ||
elevator.go_to_floor(elevator.passengers[0].dest_floor); | ||
} | ||
} | ||
|
||
log() << "Hello " << myElevators[0]; | ||
} | ||
|
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,17 @@ | ||
#ifndef STRATEGY_H | ||
#define STRATEGY_H | ||
|
||
#include <vector> | ||
#include "base_strategy.h" | ||
#include "api.h" | ||
|
||
class Strategy : public BaseStrategy | ||
{ | ||
public: | ||
void on_tick(const std::vector<Elevator>& myElevators, | ||
const std::vector<Passenger>& myPassengers, | ||
const std::vector<Elevator>& enemyElevators, | ||
const std::vector<Passenger>& enemyPassengers); | ||
}; | ||
|
||
#endif |
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,10 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
project(cppclient) | ||
|
||
SET(CMAKE_CXX_FLAGS "-D_LINUX -g -std=c++14 -g -Wall -Wno-unknown-pragmas") | ||
|
||
FILE(GLOB sources core/*.cpp csimplesocket/*.cpp csimplesocket/*.h) | ||
add_executable(cppclient main.cpp ${sources}) | ||
|
||
install(TARGETS cppclient RUNTIME DESTINATION bin) | ||
|
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,25 @@ | ||
set COMPILER_PATH= | ||
|
||
if "%GCC6_HOME%" neq "" ( | ||
if exist "%GCC6_HOME%\bin\g++.exe" ( | ||
set COMPILER_PATH="%GCC6_HOME%\bin\" | ||
) | ||
) | ||
|
||
SetLocal EnableDelayedExpansion EnableExtensions | ||
|
||
set FILES= | ||
|
||
for %%i in (*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
for %%i in (core\*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
for %%i in (csimplesocket\*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
"%COMPILER_PATH:"=%g++.exe" -std=c++14 -static -fno-optimize-sibling-calls -fno-strict-aliasing -DWIN32 -lm -s -x c++ -Wl,--stack=268435456 -O2 -Wall -Wno-unknown-pragmas -o MyStrategy.exe!FILES! -lws2_32 -lwsock32 2>compilation.log |
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,18 @@ | ||
files="" | ||
|
||
for i in core/*.cpp | ||
do | ||
files="$files $i" | ||
done | ||
|
||
for i in ./*.cpp | ||
do | ||
files="$files $i" | ||
done | ||
|
||
for i in csimplesocket/*.cpp | ||
do | ||
files="$files $i" | ||
done | ||
|
||
g++ -std=c++14 -static -fno-optimize-sibling-calls -fno-strict-aliasing -D_LINUX -lm -s -x c++ -O2 -Wall -Wno-unknown-pragmas -o MyStrategy.out $files 2>compilation.log |
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,39 @@ | ||
@echo off | ||
|
||
set VS_VERSION= | ||
|
||
if "%VS_VERSION%" == "" ( | ||
if "%VS140COMNTOOLS%" neq "" ( | ||
call "%VS140COMNTOOLS%\vsvars32.bat" | ||
call "%VS140COMNTOOLS%\..\..\VC\bin\vcvars32.bat" | ||
set VS_VERSION="140" | ||
echo Compiling with Visual Studio 2015 | ||
) | ||
) | ||
|
||
if "%VS_VERSION%" == "" ( | ||
echo No Visual Studio installation has been found | ||
exit 1 | ||
) | ||
|
||
echo *** | ||
|
||
del /F /Q MyStrategy.exe | ||
|
||
SetLocal EnableDelayedExpansion EnableExtensions | ||
|
||
set FILES= | ||
|
||
for %%i in (*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
for %%i in (core\*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
for %%i in (csimplesocket\*.cpp) do ( | ||
set FILES=!FILES! %%i | ||
) | ||
|
||
cl /FeMyStrategy.exe /W3 /F268435456 /EHsc /O2 /DWIN32 /D_WINSOCK_DEPRECATED_NO_WARNINGS ws2_32.lib!FILES! 1>compilation.log |
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,76 @@ | ||
#ifndef API_H | ||
#define API_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class Elevator; | ||
|
||
class Passenger { | ||
public: | ||
int id; // идентификатор | ||
double x, y; // координаты | ||
double weight; | ||
int from_floor, dest_floor; // этаж появления и цели | ||
int time_to_away; | ||
std::string type; | ||
int floor; | ||
int elevator; // идентификатор назначенного лифта | ||
int state; | ||
|
||
bool has_elevator() const | ||
{ | ||
return elevator != -1; | ||
} | ||
|
||
int get_last_set_elevator_id() const | ||
{ | ||
if (!set_elevator_ids.empty()) | ||
return *set_elevator_ids.rbegin(); | ||
return -1; | ||
} | ||
|
||
void set_elevator(const Elevator& elevator) const; | ||
private: | ||
mutable std::vector<int> set_elevator_ids; | ||
friend class Client; | ||
}; | ||
|
||
class Elevator { | ||
public: | ||
int id; | ||
double y; | ||
std::vector<Passenger> passengers; | ||
double speed; | ||
int time_on_floor; | ||
int next_floor; | ||
std::string type; | ||
int floor; | ||
int state; | ||
|
||
int get_last_go_to_floor() const | ||
{ | ||
if (!go_to_floor_floors.empty()) | ||
return *go_to_floor_floors.rbegin(); | ||
return -1; | ||
} | ||
|
||
public: | ||
void go_to_floor(int floor) const; | ||
|
||
private: | ||
mutable std::vector<int> go_to_floor_floors; | ||
friend class Client; | ||
}; | ||
|
||
inline void Passenger::set_elevator(const Elevator &elevator) const | ||
{ | ||
set_elevator_ids.push_back(elevator.id); | ||
} | ||
|
||
inline void Elevator::go_to_floor(int floor) const | ||
{ | ||
go_to_floor_floors.push_back(floor); | ||
} | ||
|
||
#endif // API_H |
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,29 @@ | ||
#ifndef BASE_STRATEGY_H | ||
#define BASE_STRATEGY_H | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <sstream> | ||
#include <utility> | ||
|
||
class BaseStrategy | ||
{ | ||
private: | ||
std::vector<std::pair<bool/*is exception*/, std::stringstream>> logs; | ||
friend class Client; | ||
public: | ||
|
||
std::stringstream &log() | ||
{ | ||
logs.push_back(std::make_pair(false, std::stringstream())); | ||
return logs.rbegin()->second; | ||
} | ||
|
||
std::stringstream & exception() | ||
{ | ||
logs.push_back(std::make_pair(true, std::stringstream())); | ||
return logs.rbegin()->second; | ||
} | ||
}; | ||
|
||
#endif // BASE_STRATEGY_H |
Oops, something went wrong.