#include "stdafx.h"
#include "CaroDllVS2005.h"
#include <windows.h>
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
int* cells[MAX];
int X, O;
int isX;
int rows, columns;
int row, column;
int quitSet;
EXPORT char * GetInfor()
{
return "<MSSV>";
}
EXPORT void BeginGame(int totalSet, int X, int O, int isX, int first, int vsPerson)
{
::X = X;
::O = O;
}
EXPORT void EndGame(int reason)
{
}
EXPORT int BeginSet(int set, int isX, int first)
{
::isX = isX;
return 1;
}
EXPORT int EndSet(int set, int reason)
{
return 1;
}
DWORD WINAPI Play( LPVOID lpParam )
{
for(int r = 0; r < rows; r++)
for(int c = 0; c < columns; c++)
if(cells[r][c] == 0)
{
row = r;
column = c;
return 1;
}
return 1;
}
EXPORT int Move(int cells[][MAX], int rows, int columns, int maxTime, int &row, int &column, int &timeout)
{
for(int i = 0; i < MAX; i++)
::cells[i] = &(cells[i][0]);
::rows = rows;
::columns = columns;
::quitSet = 0;
DWORD id;
HANDLE hThread = CreateThread(NULL, 0, Play, 0, 0, &id);
DWORD r = WaitForSingleObject(hThread, maxTime);
if(r == WAIT_TIMEOUT)
{
TerminateThread(hThread, 0);
timeout = 1;
return 1;
}
else
{
CloseHandle(hThread);
timeout = 0;
row = ::row;
column = ::column;
if(::quitSet)
return 0;
return 1;
}
}