[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jessica Lawrence wrote:Statistics should also display the number of times the player lied to the computer, and don't include those games in the statistics. I do not know how to tell if the player lied to the computer.
Junilu Lacar wrote:you obviously don't have it guess randomly, right?
Junilu Lacar wrote: (...)
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:What is wrong with an algorithm that guesses randomly (assuming it will always lead to the correct outcome)?
There are three kinds of actuaries: those who can count, and those who can't.
Junilu is right. It might make us look like fusspots saying that sort of thing, but we see lots of people who have strange things happening to their code and becausee they haven't indented it according to one of the well‑known conventions. It is even more confusing when the actual indentation error slips past the compiler; we even see people who write classes inside other classes because they haven't got their {} propperly matched. You will doubtless be aware of the use of a decent text editor (see this old post of mine and our FAQ) , but you will know nothing about writing backwards, but both those things will help with formatting.Junilu Lacar wrote:. . . Format your code properly . . .
Piet Souris wrote:
Coming to the question of statistics:
suppose you have a class 'GameStatistics', having the fields 'numberOfGamesPlayed' and 'TotalNumberOfGuesses', and has a method 'addNewData(int nrOfGuesses). (and orf course a method that cauculates the average number of guesses).
When you initialize your game, you can create two instance fields, 'computerStats' and 'humanStats', that you initialize with, say,
and likewise for the human.
Whenever a guessing session ends, you update the statistics for the player at hand.
Having that, you should be able to present the stats.
Junilu Lacar wrote:
Junilu Lacar wrote:you obviously don't have it guess randomly, right?
Well, color me disappointed. Looks like you did somewhat have the computer guess randomly. Why would you do that? The Binary Search algorithm would guarantee that the computer will need no more than 9 tries to guess a number between 1 and 500, assuming it is always given the correct clues. (2^9 = 512) That algorithm always start at the halfway point of the possible range of numbers. You're starting at some random point within the possible range. That simulates what a naive human player would do. A logical player will use the Binary search algorithm for maximum efficiency.
Piet Souris wrote:Well, if you were my professor, I guess we would be in for some firm discussions then!
![]()
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:@Junilu
Forget about opnions and logic, let's fight this out in a way that real men fight it out: you black belt Aikido against me, blue belt Jiu-Jitsu and Karate! And help atributes like walking sticks and rollators are out, of course!![]()
There are three kinds of actuaries: those who can count, and those who can't.
Consider Paul's rocket mass heater. |