Trying to simulate a turtle race and getting my ass kicked...
So I have a assignment to make a 5 player turtle race, but I'm having a hard time trying to implement the turtle movement and the race itself, I have been trying to this for 2 days and I feel i'm getting nowhere...
Could anyone explain ways that I could implement them into the code?
The assignment has some criterias:
- must use System.Threading and Thread
- race must me 100m
- turtle must have a random inicial velocity between 1 and 5 m/s
- during the race, the turtle must randomly have its speed increased, decreased or completely stop(sleep)
- if a draw happen, the turtle with the least time sleeping wins
- and of course, no use of AI, and code can't be copied from the internet
Also, I'm using GDB Online, because I'm in windowns 7 hell...
8 Replies
Here is what I coded so far:
https://paste.mod.gg/ttfecjjwrdvn/0
BlazeBin - ttfecjjwrdvn
A tool for sharing your source code with the world!
Have fun
Which part are you having problem with?
can be shorttened to
not integral, but nice to know
Mostly the Run() part, every time I try develop it either not works or it becomes really slow.
Also, I don't know if what I'm doing is the correct way or not, so I ge very lost...
Oh, thanks.
I didn't knew that.
to do everything in parallel with threads, you can do something like
You'll still need to figure out how to stop the task looping, report winning, and in general make sure every task is running at the same "rate" or use fastest "rate" to determine winner. That's how you get started with the multithreaded portion though
If you need to use
System.Threading.Thread
you can follow https://learn.microsoft.com/en-us/dotnet/standard/threading/using-threads-and-threading#how-to-create-and-start-a-new-thread and do similarUsing threads and threading - .NET
Learn about using threads and threading in .NET, so you can write applications to perform many operations at the same time (multithreading).
Okay thanks.
Except the assignment says they must use Thread.
The course material was probably written before the TPL existed :\