Public Group

This topic is 1820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a main thread to run (ProcessPlayerMoves)
void StartGame()
{
{
}
else
{
}
}
Then the players method is as follows:
private sMove GetMoveForPlayer(Player p)
{
lastMove = null;

//Register a listener
p.PlayerMoved += new PlayerMovedHandler(player_PlayerMoved);

// lastMove is assigned in the player_PlayerMoved handler
while (lastMove == null)
;

// if we get here the player moved

//Unregister the listenter
p.PlayerMoved -= player_PlayerMoved;

// Intervel Delay for the main thread
if (chkSimulationDelay.Checked)

try
{
}
{
Console.WriteLine(tae.ToString());
}
return p.CurrentMove;
}

During simulation there is no consitentcy, if i want to run say 500 games it just halts at 20 or sometimes 100 or 50. And i do not get an error, the game just stops but the program is still running. Edited by swiftcoder
Please use [code][/code] tags in the future.

Share on other sites

Not sure how to respond here.. It seems you are using threads, yet you don't know any of the basics of threading

Memory barriers, locking, synchronization, not using sleeping, and most important of all: not spamming threads

Threads are expensive to create, and cheap to maintain

I also don't believe any of your example code is inherently parallell as you have written it, unless of course all of these are immutable objects

Seriously though, are you sure you want to go through this nightmare?

Threading isn't something programmers CHOOSE to use, it's something you use because there's no other way.

(Or you have something that is shamefully parallell that doesn't cause side-effects, which is ultra-rare)

An example:

// use 100% cpu while waiting for reference to change, all the while all cores using this cache line constantly re-synchronize

while (lastMove == null);

And a last tip: I don't know about your language, but when a thread just stops responding it:

* could be in an infinite loop

* could have crashed

* stuck on a lock

* never 'finished' completely

* waiting for signal

Edited by Kaptein

Share on other sites

Definately true as you put it, I do not have a background at all when it comes to threading etc.

I do not have much choice, because of the way I have decided to design my

application (card game). Nevertheless I found a solution the my problem and

all seems to work fine.

After this project I will look extensively at how to use threading and more

specifically Parallel Programming incase for future needs.

Share on other sites

You're really making things much harder for yourself trying to use threads for these games.  I guarantee you the games you are making have no NEED to use threads.

I'm a professional programmer, and I've worked with threads, and I understand how they should be used, and all the tools to use to avoid the inherent pitfalls threads come with:  Yet, for all the games I've made, I've never once used threads in them.

I've made simple board games, multiplayer poker games, multiplayer Real Time Strategy games, action games, and multi player action games, and have yet needed to use threads.  The one time I did use threads was for a multiplayer engine I wrote to handle the asynchronous incoming data from all the open sockets.

I would HIGHLY recommend you take threads out of your design, and use the typical game loops:

while(IsRunning) {

// update anything related to the map I'm on
Map.Update();

// Handle the player's Input and movements
Player.Update();

// handle all the enemies
for (uint32_t i = 0; i < Enemies.size(); ++i) {
Enemies[i].Update();
}

// Now Draw Everything
// ...
}


Something like that.

Share on other sites

BeerNutts I can see you are a pro, but when i said I had no choice meaning considering alot of things I just got some samples codes of similar

implementation and tried to understand the appoach and it did work well for me.

I dont mind sending you my source code and see what i am trying to do or what i have done.

It is actually a Card game with an AI for a final project.

Edited by stoneyrich

Share on other sites

Go ahead and post a link to your code here, I'll take a look, but others would be able to help too.

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• Forum Statistics

• Total Topics
631752
• Total Posts
3002091
×