diff --git a/CAPI/AI.vcxproj b/CAPI/AI.vcxproj
index 2169af0..a82a61f 100644
--- a/CAPI/AI.vcxproj
+++ b/CAPI/AI.vcxproj
@@ -146,7 +146,7 @@
NotUsing
true
false
- EnableAllWarnings
+ Level1
WIN32;_WINDOWS;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
$(IntDir)
@@ -188,12 +188,11 @@
NotUsing
true
false
- EnableAllWarnings
+ Level1
WIN32;_WINDOWS;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)
$(IntDir)
- MultiThreaded
WIN32;_DEBUG;_WINDOWS;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)
@@ -210,7 +209,7 @@
gmock.lib;gmock_main.lib;libprotobuf.lib;libprotobuf-lite.lib;libprotoc.lib;pthreadVSE2.lib;HPSocket.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib
./windows_only/lib;./windows_only/lib/$(Configuration);%(AdditionalLibraryDirectories)
- %(AdditionalOptions) /machine:x86
+ %(AdditionalOptions) /machine:x64
true
%(IgnoreSpecificDefaultLibraries)
./Debug/AI.lib
@@ -231,7 +230,7 @@
NotUsing
true
false
- EnableAllWarnings
+ Level1
WIN32;_WINDOWS;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
$(IntDir)
@@ -266,14 +265,14 @@
.\windows_only\include;.\include;.\windows_only\proto_files;%(AdditionalIncludeDirectories)
- %(AdditionalOptions) -O3
+ %(AdditionalOptions)
$(IntDir)
CompileAsCpp
Sync
NotUsing
true
false
- EnableAllWarnings
+ Level1
WIN32;_WINDOWS;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)
$(IntDir)
@@ -485,6 +484,7 @@
+
@@ -495,8 +495,6 @@
-
-
diff --git a/CAPI/AI.vcxproj.filters b/CAPI/AI.vcxproj.filters
index a9e052c..2a142cb 100644
--- a/CAPI/AI.vcxproj.filters
+++ b/CAPI/AI.vcxproj.filters
@@ -13,6 +13,9 @@
Source Files
+
+ Source Files
+
Source Files
diff --git a/CAPI/AI.vcxproj.user b/CAPI/AI.vcxproj.user
index c542ce4..e14d459 100644
--- a/CAPI/AI.vcxproj.user
+++ b/CAPI/AI.vcxproj.user
@@ -8,4 +8,12 @@
127.0.0.1 30000
WindowsLocalDebugger
+
+ 127.0.0.1 30000
+ WindowsLocalDebugger
+
+
+ 127.0.0.1 30000
+ WindowsLocalDebugger
+
\ No newline at end of file
diff --git a/CAPI/include/CAPI.h b/CAPI/include/CAPI.h
index a4191db..1dc5425 100644
--- a/CAPI/include/CAPI.h
+++ b/CAPI/include/CAPI.h
@@ -9,6 +9,7 @@
#include "Constant.h"
#include
#include
+#include "Sema.h"
using namespace std;
@@ -44,6 +45,8 @@ class CAPI
Constant::Player player;
bool Closed;
bool PauseUpdate;
+ Sema sema;
+ Sema start_game_sema;
private:
CListenerImpl listener;
diff --git a/CAPI/include/Sema.h b/CAPI/include/Sema.h
new file mode 100644
index 0000000..8d0ef3e
--- /dev/null
+++ b/CAPI/include/Sema.h
@@ -0,0 +1,19 @@
+#pragma once
+#ifndef SEMA_H
+#define SEMA_H
+#endif // !SEMA_H
+
+#include
+#include
+
+class Sema
+{
+private:
+ std::mutex mu;
+ std::condition_variable cv;
+
+public:
+ void notify();
+ void wait();
+};
+
diff --git a/CAPI/include/structures.h b/CAPI/include/structures.h
index 5eb9738..066ffe8 100644
--- a/CAPI/include/structures.h
+++ b/CAPI/include/structures.h
@@ -145,4 +145,6 @@ class player_info
};
extern player_info PlayerInfo;
+extern long long getSystemTime();
+
#endif // !STRUCTURES_H
\ No newline at end of file
diff --git a/CAPI/modify.py b/CAPI/modify.py
index c62ef9d..c96d69b 100644
--- a/CAPI/modify.py
+++ b/CAPI/modify.py
@@ -9,4 +9,6 @@
lines = open(doc, encoding="utf-8").readlines()
fp = open(doc, 'w', encoding="utf-8")
for s in lines:
- fp.write(s.replace("..\\", ".\\"))
+ str = s.replace(pwd2, ".")
+ str = str.replace(pwd, ".")
+ fp.write(str)
diff --git a/CAPI/src/API.cpp b/CAPI/src/API.cpp
index 59e7570..a1daecd 100644
--- a/CAPI/src/API.cpp
+++ b/CAPI/src/API.cpp
@@ -10,13 +10,6 @@ extern CAPI API;
unsigned long long THUAI3::initGameTime;
-long long getSystemTime()
-{
- timeb t;
- ftime(&t);
- return t.time * 1000 + t.millitm;
-}
-
int THUAI3::GetPing()
{
return API.Ping;
diff --git a/CAPI/src/CAPI.cpp b/CAPI/src/CAPI.cpp
index 374b9eb..1739ae4 100644
--- a/CAPI/src/CAPI.cpp
+++ b/CAPI/src/CAPI.cpp
@@ -17,6 +17,7 @@
#include
#include "structures.h"
#include "player.h"
+#include "Sema.h"
#pragma comment(lib, "HPSocket.lib")
#include
@@ -162,6 +163,11 @@ void CAPI::SendChatMessage(string message)
void CAPI::SendCommandMessage(MessageToServer message)
{
+ static long long lastSendTime = 0;
+ long long now = getSystemTime();
+ if (now < lastSendTime + 50)
+ return;
+ lastSendTime = now;
MessageToServer* mes0 = new MessageToServer(message);
Message* mes2 = new Message(PlayerId, mes0);
Message* mes3 = new Message(-1, mes2);
@@ -217,8 +223,9 @@ void CAPI::UpdateInfo(Protobuf::MessageToClient* message)
mesC2S.set_issettalent(true);
mesC2S.set_talent(initTalent);
SendCommandMessage(mesC2S);
- GameRunning = true;
std::cout << "Game start" << std::endl;
+ GameRunning = true;
+ start_game_sema.notify();
}
google::protobuf::Map::const_iterator self_iter = message->gameobjectlist().find(PlayerInfo._id);
if (self_iter != message->gameobjectlist().end())
@@ -233,15 +240,6 @@ void CAPI::UpdateInfo(Protobuf::MessageToClient* message)
PlayerInfo.tool = self_iter->second.tooltype();
PlayerInfo.recieveText = self_iter->second.recievetext();
}
- //Protobuf::GameObject self = message->gameobjectlist().at(PlayerInfo._id);
- //PlayerInfo._position.x = PlayerInfo.position.x = self.positionx();
- //PlayerInfo._position.y = PlayerInfo.position.y = self.positiony();
- //PlayerInfo.facingDirection = self.direction();
- //PlayerInfo.moveSpeed = self.movespeed();
- //PlayerInfo.sightRange = PlayerInfo._sightRange = self.sightrange();
- //PlayerInfo.dish = self.dishtype();
- //PlayerInfo.tool = self.tooltype();
- //PlayerInfo.recieveText = self.recievetext();
if (message->scores().contains(PlayerInfo._team))
PlayerInfo.score = message->scores().at(PlayerInfo._team);
@@ -262,6 +260,7 @@ void CAPI::UpdateInfo(Protobuf::MessageToClient* message)
{
task_list.push_back((DishType)(*i));
}
+ sema.notify();
}
diff --git a/CAPI/src/Sema.cpp b/CAPI/src/Sema.cpp
new file mode 100644
index 0000000..0586dfd
--- /dev/null
+++ b/CAPI/src/Sema.cpp
@@ -0,0 +1,14 @@
+#include "Sema.h"
+#include
+#include
+
+void Sema::notify()
+{
+ std::unique_lock locker(mu);
+ cv.notify_one();
+}
+void Sema::wait()
+{
+ std::unique_lock locker(mu);
+ cv.wait(locker);
+}
diff --git a/CAPI/src/main.cpp b/CAPI/src/main.cpp
index cbac1b5..0dd33f8 100644
--- a/CAPI/src/main.cpp
+++ b/CAPI/src/main.cpp
@@ -15,6 +15,7 @@
#include "player.h"
#include "API.h"
#include "OS_related.h"
+#include "Sema.h"
using namespace std;
@@ -51,11 +52,12 @@ int main(int argc, char* argv[])
while (!GameRunning)
{
- Sleep(1);
+ API.start_game_sema.wait();
}
THUAI3::initializeGameTime();
while (GameRunning)
{
+ API.sema.wait();
play();
}
getchar();
diff --git a/CAPI/src/player.cpp b/CAPI/src/player.cpp
index d1d70f1..8bff409 100644
--- a/CAPI/src/player.cpp
+++ b/CAPI/src/player.cpp
@@ -4,7 +4,7 @@
#include
#include "OS_related.h"
using namespace THUAI3;
-Protobuf::Talent initTalent = Protobuf::Talent::Runner;//指定人物天赋。选手代码必须定义此变量,否则报错
+Protobuf::Talent initTalent = Protobuf::Talent::None;//指定人物天赋。选手代码必须定义此变量,否则报错
void play()
{
char c;
@@ -18,6 +18,7 @@ void play()
int moveDistance = 0;
std::cout << endl << "Please Input your move distance" << endl;
cin >> moveDistance;
+ cout << moveDistance / PlayerInfo.moveSpeed * 1000 << endl;
move(Protobuf::Direction::Right, moveDistance / PlayerInfo.moveSpeed * 1000);
}break;
case 'e':
diff --git a/CAPI/src/structure.cpp b/CAPI/src/structure.cpp
index 7b83f22..a069e34 100644
--- a/CAPI/src/structure.cpp
+++ b/CAPI/src/structure.cpp
@@ -121,3 +121,10 @@ std::list MapInfo::get_mapcell(const int x, const int y)
Obj::Obj(const XYPosition& pos, ObjType objType) : position(pos), objType(objType)
{ }
player_info PlayerInfo;
+
+long long getSystemTime()
+{
+ timeb t;
+ ftime(&t);
+ return t.time * 1000 + t.millitm;
+}
diff --git a/communication/Agent/Program.cs b/communication/Agent/Program.cs
index 5d35909..f1f782e 100644
--- a/communication/Agent/Program.cs
+++ b/communication/Agent/Program.cs
@@ -13,7 +13,7 @@ public class Program
private static IDServer server = new IDServer();
private static System.Timers.Timer myTimer = new System.Timers.Timer();
private static IPEndPoint Server;
- private static object LastSpam;// = Constants.MaxMessage;
+ private static object[] LastSpam;// = Constants.MaxMessage;
/*
private static void TimeCount(object source, System.Timers.ElapsedEventArgs e) //倒计时
{
@@ -36,6 +36,7 @@ public static void Main(string[] args)
Constants.PlayerCount = ushort.Parse(playercount.Value());
if (Constants.PlayerCount < 1) Constants.PlayerCount = 1;
else if (Constants.PlayerCount > 2) Constants.PlayerCount = 2;
+ LastSpam = new object[Constants.PlayerCount];
//Constants.MaxMessage = int.Parse(messagelmt.Value());
Constants.TimeLimit = double.Parse(timelmt.Value());
if (Constants.TimeLimit < 10) Constants.TimeLimit = 10;
@@ -52,7 +53,8 @@ private static int MainInternal(string ep, ushort port, string token, int debugL
server.Port = port;
Constants.Debug("Agent Listen Port: " + server.Port.ToString());
Constants.Debug("Client Token: " + (token ?? ""));
- LastSpam = Environment.TickCount;
+ for (int i = 0; i < LastSpam.Length; i++)
+ LastSpam[i] = Environment.TickCount;
//init timer
myTimer.Interval = Interval;
@@ -74,8 +76,13 @@ private static int MainInternal(string ep, ushort port, string token, int debugL
var now = Environment.TickCount;
lock (LastSpam)
{
- if (now <= (int)LastSpam + Constants.TimeLimit) return;
- LastSpam = now;
+ if (now <= (int)LastSpam[0] + Constants.TimeLimit) return;
+ for (int i = 1; i < Constants.PlayerCount; i++)
+ {
+ LastSpam[i - 1] = LastSpam[i];
+ }
+ LastSpam[Constants.PlayerCount - 1] = now;
+ Console.WriteLine(now);
}
}
else
diff --git a/logic/THUnity2D/GameObject.cs b/logic/THUnity2D/GameObject.cs
index 26c0176..9cc97bb 100644
--- a/logic/THUnity2D/GameObject.cs
+++ b/logic/THUnity2D/GameObject.cs
@@ -359,10 +359,8 @@ public virtual void Move(double angle, double distance)
lock (privateLock)
{
if (!this._movable)
- {
return;
- }
- if ((DateTime.Now - lastMoveTime).TotalSeconds < 1 / _frameRate)
+ if ((DateTime.Now - lastMoveTime).TotalSeconds < 0.7 / _frameRate)
return;
lastMoveTime = DateTime.Now;
MoveStart?.Invoke(this);
diff --git a/runAgent.bat b/runAgent.bat
index 2ac41aa..d3fc9e1 100644
--- a/runAgent.bat
+++ b/runAgent.bat
@@ -1 +1 @@
-communication\Agent\bin\Release\netcoreapp3.0\Communication.Agent.exe --server 127.0.0.1:20000 --port 30000 --debugLevel 0 --playercount 2 --timelimit 25
\ No newline at end of file
+communication\Agent\bin\Release\netcoreapp3.0\Communication.Agent.exe --server 127.0.0.1:20000 --port 30000 --debugLevel 0 --playercount 2 --timelimit 50
\ No newline at end of file
diff --git a/runServer.bat b/runServer.bat
index 2a35ba8..cb63ddf 100644
--- a/runServer.bat
+++ b/runServer.bat
@@ -1 +1 @@
-logic\Logic.Server\bin\Release\netcoreapp3.0\Logic.Server.exe --port 20000 --debugLevel 1 --playerCount 2 --agentCount 4 --gameTime 600
\ No newline at end of file
+logic\Logic.Server\bin\Release\netcoreapp3.0\Logic.Server.exe --port 20000 --debugLevel 1 --playerCount 2 --agentCount 1 --gameTime 600
\ No newline at end of file