[QUOTE=Duskling;45751202]First off, I think there is a special import in order to use that math class, but I could be wrong. It's been a while since I've touched it.
Secondly, you are using it wrong. This is what you should do:
[CODE]Random rand = new Random(); // create a new random.
int number = rand.nextInt(100) + 1; // get a random number between 1 and 100.[/CODE]
Third, your loop seems to be in need of a few modifications. You can simplify the loop itself by doing this:
[CODE]
while(guess != randomNumber)
[/CODE]
and you are getting a new random number every time the loop runs, which means that the player is just guessing at a different number each time. Once you fix your random number generation (shown above) you would place it outside and above the while loop so that at the start of the game, it would generate one random number for the entire game.
Lastly, in this if block:
[CODE]
else if (guess == randomNumber)
{
System.out.println("You guessed correctly! :)");
}
[/CODE]
You are checking if the place has won the game. In order to break out of the while loop and display congratulations, you would have to place a break; after the println. This should exit the while loop and display "Congratulations".[/QUOTE]
Thanks man! :)
To answer your question about Math.random, it's a function so you have to have parenthesis:
[code]double r = Math.random();[/code]
No imports needed (anything in the java.lang package is implicitly imported). 0 <= Math.random() < 1
I'm trying to find some resources to help me grasp how you would manage a multithreaded environment in c++
help.
[QUOTE=Mechanical43;45752750]I'm trying to find some resources to help me grasp how you would manage a multithreaded environment in c++
help.[/QUOTE]
[url]http://en.cppreference.com/w/cpp/thread[/url]
Just search for general multi-threading stuff. The concepts transfer very easily.
[QUOTE=Mechanical43;45752750]I'm trying to find some resources to help me grasp how you would manage a multithreaded environment in c++
help.[/QUOTE]
This explains it very well and uses the new C++11 stuff [url]http://www.amazon.com/C-Concurrency-Action-Practical-Multithreading/dp/1933988770[/url]
does anyone know how to use QT? i have tried looking at tutorials but it just doesn't do the justice for me, all i really want to know is does it work similar like VS's editor pre 2010? like for example you have a gui button right? and in the code it has the button name and the curly brackets under it and you insert your code there. I haven't really got to touch it much and i for some reason lacked the motivation to code lately and im going to dive back into it but i just wanted to know so i could get a basic grasp on QT and work with gui for a minute.
[QUOTE=Mechanical43;45752750]I'm trying to find some resources to help me grasp how you would manage a multithreaded environment in c++
help.[/QUOTE]
[url]https://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/[/url]
There are also part 2 and 3. The blog is very good too, filled with C++(,11,14) goodies.
What is it called when AI agent learns from previous mistakes/actions or uses previous outputs as tips for future actions/processes?
Is it self aware? or self learning? or is there more specific name for this?
[QUOTE=confinedUser;45755726]does anyone know how to use QT? i have tried looking at tutorials but it just doesn't do the justice for me, all i really want to know is does it work similar like VS's editor pre 2010? like for example you have a gui button right? and in the code it has the button name and the curly brackets under it and you insert your code there. I haven't really got to touch it much and i for some reason lacked the motivation to code lately and im going to dive back into it but i just wanted to know so i could get a basic grasp on QT and work with gui for a minute.[/QUOTE]
QT comes with a hell lot of example apps... check them out... i think it's always better to check out examples. I learn from those the most.
[QUOTE=KinderBueno;45758306]What is it called when AI agent learns from previous mistakes/actions or uses previous outputs as tips for future actions/processes?
Is it self aware? or self learning? or is there more specific name for this?[/QUOTE]
Self learning I think. Or "learning" in the first place, for that matter.
Also trying to read and kinda get into how computer understands human language, as in say you have sentence:
"Find me a closest petrol station"
and
"closest petrol station to me"
How would AI understand where to look and what to look for?
Is there like specific key words like: Find, Do, Search, Call, Text, Cancel (Verbs) then looks for nouns like: restaurant, petrol, shop, motorway etc..?
Anyone have any nice resource where I can read on about it? But something that I can understand, I tried looking but some of the explanations are very hard to understand.
Thanks.
What is the general consensus on this 80 character line in Netbeans, is 80 characters a good point wrap the code down to the next line or should I ignore it? Code is in C if that matters.
[IMG]http://i.imgur.com/wGybMEg.png[/IMG]
[QUOTE=Cittidel;45759657]What is the general consensus on this 80 character line in Netbeans, is 80 characters a good point wrap the code down to the next line or should I ignore it? Code is in C if that matters.
[IMG]http://i.imgur.com/wGybMEg.png[/IMG][/QUOTE]
I was taught 72 but its a quibbling distinction between 80 and 72 tbh. Between 70-80 is good.
[QUOTE=confinedUser;45755726]does anyone know how to use QT? i have tried looking at tutorials but it just doesn't do the justice for me, all i really want to know is does it work similar like VS's editor pre 2010? like for example you have a gui button right? and in the code it has the button name and the curly brackets under it and you insert your code there. I haven't really got to touch it much and i for some reason lacked the motivation to code lately and im going to dive back into it but i just wanted to know so i could get a basic grasp on QT and work with gui for a minute.[/QUOTE]
That's not how Qt works.
Qt uses a signal and slot mechanic. For some extremely simple cases, it is enough to drag a line between two widgets in the editor to make things work. But in general you define a class with slot methods, do your logic there and connect the widgets' signals to them. In C++11 you can connect a signal to a lambda to handle it.
[QUOTE=Cittidel;45759657]What is the general consensus on this 80 character line in Netbeans, is 80 characters a good point wrap the code down to the next line or should I ignore it? Code is in C if that matters.
[IMG]http://i.imgur.com/wGybMEg.png[/IMG][/QUOTE]
You could just enable line wrapping, I use that in VS and it's very convenient.
[sp]Please don't hurt me.[/sp]
[QUOTE=Tamschi;45767940]You could just enable line wrapping, I use that in VS and it's very convenient.
[sp]Please don't hurt me.[/sp][/QUOTE]
I agree with this actually. Personally line wrapping isn't really an issue for me since I run VS in fullscreen but I understand that a fair amount of people dont like their code running off the edge of their screen. I'm not sure if vs lets you specify the amount of characters to wrap at or not though.
Lines longer than 80 characters are usually harder to read. It's easier to move your eyes up or down a few lines than left or right a few dozen characters. Depending on the company you work for you may be required to have everything within 80 characters.
[QUOTE=Fredo;45771905]Lines longer than 80 characters are usually harder to read. It's easier to move your eyes up or down a few lines than left or right a few dozen characters. Depending on the company you work for you may be required to have everything within 80 characters.[/QUOTE]
Depends on a few things I guess. For me its easier to read long lines than wrapped code. That being said, a lot of coding styles are designed to try and eliminate long lines of code, so wrapping isnt really needed unless you have a 648x480 screen or something :v:
[QUOTE=Fredo;45771905]Lines longer than 80 characters are usually harder to read. It's easier to move your eyes up or down a few lines than left or right a few dozen characters. Depending on the company you work for you may be required to have everything within 80 characters.[/QUOTE]
I'm fairly sure the 80 character limit is because old video terminals used to only have 80 columns.
[editline]23rd August 2014[/editline]
That said, I stick to it myself. Long lines are difficult to read, wrapped infinitely more so.
[QUOTE=esalaka;45771956]I'm fairly sure the 80 character limit is because old video terminals used to only have 80 columns.
[editline]23rd August 2014[/editline]
That said, I stick to it myself. Long lines are difficult to read, wrapped infinitely more so.[/QUOTE]
To each his own. I'm not saying "dont wrap" or anything. If you want to use line wrapping, do it, but I dont think a lot of editors allow you choose how many characters before wrapping occurs but like I said, I dont use it so I'm not entirely sure either.
[QUOTE=esalaka;45771956]I'm fairly sure the 80 character limit is because old video terminals used to only have 80 columns.[/QUOTE]
That is the original reason, but the limit is still used all over the place.
Having an 80 character limit also lets you display multiple files at once next to each other (without worrying about line wrapping), which I tend to do a lot.
[QUOTE=G4MB!T;45770748]I agree with this actually. Personally line wrapping isn't really an issue for me since I run VS in fullscreen but I understand that a fair amount of people dont like their code running off the edge of their screen. I'm not sure if vs lets you specify the amount of characters to wrap at or not though.[/QUOTE]
Actually, I mean the function that wraps the text around into the next line for display only, when the window is too small :v:
[QUOTE=Tamschi;45774716]Actually, I mean the function that wraps the text around into the next line for display only, when the window is too small :v:[/QUOTE]
I know :0?
[QUOTE=G4MB!T;45774724]I know :0?[/QUOTE]
Oh. I was confused because you mentioned configurable line width.
Here's what my current config looks like:
[img]https://dl.dropboxusercontent.com/u/5013896/forum/Facepunch/Programming/WDYNHW/Zeilenumbruch.png[/img]
(I usually don't have the error list or tool box pinned, so there's normally more space.)
[QUOTE=Two-Bit;45745022]Hey, so I wanted to give game development a go after a few years experience in programming C#/Java and c++. I was wondering if there is like a modern guide to game development anyone recommends? It will be a game similar to like Baldur's Gate Dark Alliance and Diablo probably be done in unity.
Basically I want like a step by step guide to making a game.
Thanks guys.[/QUOTE]
How to make a game:
While loop
clear screen
draw everything
repeat while loop
and then have a bunch of methods and functions that draw things based on input
glhf
but more seriously though there ARE books on amazon that will give you step by step guides to make a generic game.
if I recall [url=http://www.amazon.com/Beginning-Java-SE-Game-Programming/dp/1435458087]this book[/url] will teach you to make asteroids using vector graphics, which are actually a little bit more math oriented than if you were to just load an image file, but the book will teach you everything. youll learn a lot about games and if you've got a creative and analytical mind you might come up with something new in the process
glhf
[editline]23rd August 2014[/editline]
[QUOTE=Two-Bit;45747988]I just don't know where to begin, how to build the skeleton of the game so to speak, how to have a rough game then be able to add the features and all that in.[/QUOTE]
The skeleton of the game; the system by which the game does all the processing before there even IS a game, how it deals with its various files and input and physics and everything, is called the game ENGINE. 2D game programming is easy. For good practice, take old arcade games and try to re-create them.
Where can I learn assembly, what version/architecture should I learn?
[QUOTE=KinderBueno;45758306]What is it called when AI agent learns from previous mistakes/actions or uses previous outputs as tips for future actions/processes?
Is it self aware? or self learning? or is there more specific name for this?[/QUOTE]
Machine Learning. The AI itself is made using a neural network with inputs and outputs. The net is made up of objects called Nodes. Nodes are setup in layers, where the first layer contains input nodes and the last layer contains output nodes. The nodes of each layer are connected to each of the nodes of the next layer, and so on. Each connection has a weight, which indicates how important that connection is to the receiving node. If a node receives an input that exceeds a set threshold value, they become excited and send an output to all of it's connections. This process continues until the output nodes produce an output. A neural net is initialised with a set number of input nodes (i.e. if you want to recognise characters inside an image you're going to have an input node for each pixel in the image representing it's grayscale value), a set number of output nodes (i.e. a node representing the ascii number of the character it recognized) and a couple of layers of neurons between the inputs and the outputs with randomised weights.
This kind of AI will suck when it's first created because the weights of each connection are random - hence you will not receive a good result when using the network upon initialisation. For example, if creating a net that recognises the presence of a character in a 20x20 image, you will initialise a net with 400 input nodes and 1 output node. However, this net will give you a random number as an output for each image you use as an input and you want the output to be 65 (ascii for A) if you present it with a 20x20 image containing the letter 'A'. You need to train the network in order to 'teach' it how to recognise letters, this is done with a training set - a set of inputs and their correct outputs.
During the training sessions, the nets are presented with an input and the weights of the neurons' connections are modified slightly until the correct output is achieved. This is done for many different types of inputs until the net yields good results.
I hope this answered your question.
[QUOTE=Tamschi;45775984]Oh. I was confused because you mentioned configurable line width.
Here's what my current config looks like:
...
(I usually don't have the error list or tool box pinned, so there's normally more space.)[/QUOTE]
Really, a variable width serif font for code?
[QUOTE=SteveUK;45777543]Really, a variable width serif font for code?[/QUOTE]
Yes, really. It's easily readable, avoids obsessing about perfect alignment, and puts a lot more characters on the screen horizontally than a monospace one.
It also feels a bit like writing a novel :v:
[editline]23rd August 2014[/editline]
You should see my MonoDevelop config, with [I]beautiful italic comments[/I]. (I think that's the default there though, I just changed the font and text size.)
It just feels... wrong...
Sorry, you need to Log In to post a reply to this thread.