[FINISHED (I think)] Cake AI

Off topicProgramming → [FINISHED (I think)] Cake AI

Hallo ther! Yesterday, I decided to start seriously learning java. A few years ago, I did some mods, but I didn’t know what I was doing at all, so this is like a fresh start for me. After a few very basic programs, I decided to make a very simple AI (if you can call it that at all). It asks a single question, you give a response, and it responds to you. However, it is difficult to think of what people will say, so please use this program and give as many logical answers as you can to find something that the program isn’t coded to respond to. If you find a response that isn’t supported, please respond to this thread and tell me. Eventually, the “AI” will be much more complex, but for now, I’m just starting out. :P

The executable: https://www.dropbox.com/s/6nivg6ec3wgta4h/CakeAI.jar?dl=0 The worst code ever: http://hastebin.com/ugepivubem.avrasm

EDIT: The AI can now learn up to 10 new custom responses! It would be more, but as you can see from the src code, it’s a lot for each response. (There is probably a much simpler way of doing this but hey I started yesterday)

I iz gud programerz then
@PeonyBT I have added your response.
Yea, it really should have meh, and Pie is better by defualt.
I shall add those @minenash
Because I am a Java noob.

Logal, I think abot even smarter than that ._.

img

Talk about bad coding style…

Sorry to tell you but that code is ugly as fuck. Consider using arrays. Lists. Anything that will get rid of those 50 nested ifs. Seriously, don’t even start doing that. I’d suggest you not starting with graphics and not starting with an AI. Instead try simple console applications to get used to the syntax and find a coding style that will fit you. No, randomly putting curly brackets everywhere is not a proper coding style :< If you need help you can always poke me on slack.

If you wanna know how an AI works I can help you out on that as well but oh boy it’s not “comparing an input to a list of possible combinations and then choosing a predefined output”… Simple AIs will use fuzzy logic. Which is anything but your “yes/no” logic but instead “this could be 80% he likes cake and 20% he doesn’t so I’ll say ‘yes cake is good’” or “I’m 90% certain that he doesn’t like cake, 5% that he hates it and 5% that he loves it - I’ll go with ‘Why do you think that cake sucks?'”.

Greetings

~Pepich~

PS: Soz for the weird reply, I’m a bit in a hurry rn :P

@Pepich1851 I know that I have the worst code in existence. I also realize that I misused the term “AI.” At this point, I am experimenting with Java, because am not skilled in coding yet. I will do what you said and create “simple console applications” to better my skills. I am currently learning how to effectively use arrays, so that will hopefully make my code much cleaner.

If you could give me an idea of what a simple console application could be, it would be greatly appreciated.

k here we go. With simple console applications I mean stuff like a console based calculator. You enter a number, you enter a 2nd number, you tell it which operation to perform and it will do it. I/O could look like this (user input is bold):

Please enter a number: 5 Please enter a second number: k “k” is not a number. Please enter a second number: 17 Please tell me what to do (1 = add, 2 = sub, 3 = mul, 4 = div) 3 5 * 17 = 85 Please enter a number: and so on

Or for example something to search your files:

Please enter a filename to find: .jpg Please enter a folder to search: C:\users\foo\bar\pictures Searching for files containing “.jpg” in their name… Random shit.jpg Nice picture.jpg You mom la… not gonna bring this joke here lol.jpg why .jpg sucks.doc Found 4 files containing .jpg in the given directory.

If you need more ideas/sample code/a compiled jar to look at how it could run feel free to ask :)

Greetings

~Pepich~

I have updated my code to be much, MUCH better. I’m sure you all will appreciate it.
That looks a million times better :D
Actually, I agree with Pepich; that code was very poorly made and definitely required revision.

There’s one single thing that is a style issue that I didn’t flag as such. The multiline variable definition. Everything else is not a style issue or is marked as such. Choosing proper variable names is not a style issue but a nessecarity when doing bigger project. Starting variables with uppercase letters is not a style issue but a java guidelines thingy. Classes start with uppercase. Variables with lower. Object Object = new Object(); And rip you. Instead you do Object object. Unnessecary code is again not a style issue but an issue of not putting unnessecary code. Using while instead of for again is not a style issue but it’s a performance question. For loops usually can be optimized a lot but while loops not really. x = x+1; vs x++; latter one is faster. Additionally he even switched between those two. Switching styles is not needed to be discussed because once you choose a style you don’t randomly jump around.

Oh and anything that’s decreasing readability shouldn’t even need to be discussed either lol

I was not aware of many of those points that you mentioned, so I will keep them in mind for the future.