Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#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];	// ban co, cells[row][column] la quan o dong row, cot column
int X, O;			// gia tri cua quan X, O tren ban co, o rong tren ban co co gia tri la 0
int isX;			// cho biet chuong trinh la quan X (isX la true) hay O (isX la false)
int rows, columns;	// so dong, so cot cua ban co
int row, column;	// chuong trinh danh tai dong row, cot column
int quitSet;		// chuong trinh muon chiu thua set hien tai

// Duoc goi de tra ve ten cua Player
EXPORT char * GetInfor()
{
	// Sinh vien can sua ham nay de tra ve MSSV
	// Vi du: return "080001";
	
	return "<MSSV>";
}

// Duoc goi khi bat dau game
// totalSet cho biet tong so set cua game
// X cho biet so nguyen dai dien cho quan X tren ban co
// O cho biet so nguyen dai dien cho quan O tren ban co
// isX la true neu chuong trinh la quan X trong set dau tien
// first la true neu chuong trinh duoc choi truoc set dau tien, cac set sau se luan phien thay doi
// vsPerson la true neu chuong trinh choi voi nguoi
EXPORT void BeginGame(int totalSet, int X, int O, int isX, int first, int vsPerson)
{
	// Sinh vien khong can sua ham nay
	
	::X = X;
	::O = O;
}

// Duoc goi khi ket thuc game
// reason cho biet li do ket thuc game
//		1 : thang
//		2 : hue
//		3 : thua
//		4 : chiu thua (thua)
//		5 : doi thu chiu thua (thang)
//		6 : Caro Master ket thuc game (hue)
EXPORT void EndGame(int reason)
{
	// Sinh vien khong can sua ham nay
}

// Duoc goi khi bat dau set
// set cho biet la set thu may cua game (tinh tu 1)
// isX la true neu chuong trinh la quan X trong set nay
// first la true neu chuong trinh duoc danh truoc trong set nay
// ham tra ve true de chap nhan choi set nay, tra ve false neu muon dau hang set nay
EXPORT int BeginSet(int set, int isX, int first)
{
	// Sinh vien khong can sua ham nay

	::isX = isX;

	return 1;
}

// Duoc goi khi ket thuc set
// set cho biet la set thu may cua game (tinh tu 1)
// reason cho biet li do ket thuc set
//		1 : hue
//		2 : doi thu di khong hop le (thang)
//		3 : doi thu het gio (thang)
//		4 : doi thu chiu thua (thang)
//		5 : thang
//		6 : di khong hop le (thua)
//		7 : het gio (thua)
//		8 : chiu thua (thua)
//		9 : thua
//		10 : Caro Master ket thuc set (hue)
// ham tra ve true de tiep tuc choi set tiep theo, tra ve false de dau hang cac set con lai cua game
EXPORT int EndSet(int set, int reason)
{
	// Sinh vien khong can sua ham nay

	return 1;
}

// Duoc goi de yeu cau chuong trinh danh
// Dung thong tin trong cac bien sau de danh: 
//		cells:	cho biet thong tin ban co, cells[row][column] la quan o dong row, cot column
//		X, O:	cho biet gia tri cua quan X, O tren ban co, o rong tren ban co co gia tri la 0
//		isX:	cho biet chuong trinh la quan X (isX la true) hay O (isX la false)
//		rows, columns: cho biet so dong, so cot cua ban co
// Chuong trinh can xac dinh o can danh bang cach dat gia tri cua bien: row, column
// Chuong trinh dat bien quitSet thanh true neu muon chiu thua set hien tai
DWORD WINAPI Play( LPVOID lpParam ) 
{
	// Sinh vien can cai dat thuat toan danh co cua minh trong ham nay
	
	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;
}

// Ham dieu khien chuong trinh danh co
// Sinh vien khong duoc phep sua ham nay
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;
	}
}
Posted
Updated 6-Oct-10 8:15am
v2
Comments
Marc A. Brown 6-Oct-10 14:17pm    
After wrapping the code in this question in a code block, I realized that I don't see an actual question. Hmm.
Sandeep Mewara 6-Oct-10 15:06pm    
UPDATE from OP:
http://www.mediafire.com/?s3hys0wia70xl1f



heuristic algorithm is too batons, please edit pro fears, needs to find a real problem for heuristic program

1 solution

Well, since this is an English-speaking site, we don't know what the comments say, much less what game this is for.
 
Share this answer
 
Comments
Member 3748012 4-May-11 3:40am    
What's a stupid teacher!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900