Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
SlaveMind Game Posted by flytofall on 7 Apr 2007 at 9:32 AM
I am working on a slavemind game project written in Java. Does anybody here have been working on that or have done that before? I really need the source code for the SlaveMind Game. This is how the game is: The game of Mastermind where one player sets up a number of pins behind a barrier and the other player guesses the colour and position of each pin is well known. The Slavemind game in this assignment is similar except it is played against the computer using numbers instead of coloured pins.
The computer generates a number consisting of five non-unique digits between 1 and 5. The human player repeatedly guesses the number, receiving feedback on the accuracy of each guess from the computer. Feedback is of the following form:
A P is awarded if a digit in the guess is correct and in the correct position. More than one P means that multiple digits are in the correct position, without saying which digits or positions they are. PPPPP means that all digits are correct and in the correct position.
An N is awarded if a digit in the guess is correct but in the wrong position.
A Z is awarded if no digits of the guess are in the target number.
So that the game is not too easy, the feedback always evaluates and displays the Ps before the Ns.

I would be very thankful if you could post a reply to this. TQ!

Report
Re: SlaveMind Game Posted by zibadian on 7 Apr 2007 at 10:22 AM
: I am working on a slavemind game project written in Java. Does anybody here have been working on that or have done that before? I really need the source code for the SlaveMind Game. This is how the game is: The game of Mastermind where one player sets up a number of pins behind a barrier and the other player guesses the colour and position of each pin is well known. The Slavemind game in this assignment is similar except it is played against the computer using numbers instead of coloured pins.
: The computer generates a number consisting of five non-unique digits between 1 and 5. The human player repeatedly guesses the number, receiving feedback on the accuracy of each guess from the computer. Feedback is of the following form:
: A P is awarded if a digit in the guess is correct and in the correct position. More than one P means that multiple digits are in the correct position, without saying which digits or positions they are. PPPPP means that all digits are correct and in the correct position.
: An N is awarded if a digit in the guess is correct but in the wrong position.
: A Z is awarded if no digits of the guess are in the target number.
: So that the game is not too easy, the feedback always evaluates and displays the Ps before the Ns.
:
: I would be very thankful if you could post a reply to this. TQ!
:
:
See Math.random() to setup the game.
Use int[] arrays to hold the numbers and a string to hold the results
The simplest way to check the results, is first to loop through the player and computer arrays and check each element 1 on 1:
  for (int i=0; i < pinCount; i++) {
    if (computer[i] == player[i]) {
      result = result + 'P';
      player[i] = -1;
    }
  }

Then check each digit out of place:
  for (int i=0; i < pinCount; i++) {
    for (int j=0; j < pinCount; j++) {
      if (computer[i] == player[i] && i != j) {
        result = result + 'N';
        player[i] = -1;
      }
    }
  }

This code needs some work to correctly display it.
The turns repeat until the results string equals all P's.
Report
SlaveMind Game SourceCode Posted by flytofall on 8 Apr 2007 at 3:18 AM
Could you please sending me the source code to the SlaveMind game written in Java? I do understand better with your suggested codes but I think I can understand it better if you could send me the whole source code. Thank you very much before hand.
Report
Re: SlaveMind Game SourceCode Posted by zibadian on 8 Apr 2007 at 3:43 AM
: Could you please sending me the source code to the SlaveMind game written in Java? I do understand better with your suggested codes but I think I can understand it better if you could send me the whole source code. Thank you very much before hand.
:
I don't have that code, and I'm unwilling to make it for you, since I've already have 3 projects running. I could be persuaded to trade with you if you like, although all my projects are much larger than this one.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.