Results 1 to 3 of 3
  1. #1
    predricted is offline Member
    Join Date
    Jan 2015
    Posts
    4
    Rep Power
    0

    Default Mastermind algorithm

    Hi all,

    I finished the player part of my mastermind game. Now i'm busy with the computer part. Now i've checked a few mastermind algorithms and have to say its difficult to implement them in my java script.
    Can anyone help me to do this?

    I am stuck at the guess phase. My code is as following
    prevGUess is the previous guess
    prevposright is the previous right guess at right position
    prevcolright is the previous right guess wrong position

    Java Code:
    	public String guessPhase(int curChance, String prevGuess, int prevPosRight, int prevColRight){
    		String posRight;
    		String colRight;
    		if(curChance == 1){
    			String letters = "ABCDEF";
    			Random r =	new Random();
    			for(int i = 0; i < guessChars.length; i++){
    				int n = r.nextInt(5);
    				guessChars[i] = letters.charAt(n);
    			}
    		}else{
    			if(posRight_p == 0 && colRight_p == 0){
    				String letters = "ABCDEF";
    				Random r =	new Random();
    				for(int i = 0; i < guessChars.length; i++){
    					int n = r.nextInt(5);
    					guessChars[i] = letters.charAt(n);
    				}	
    			}
    
    
    
    		}
    		return String.valueOf(guessChars) + posRight + colRight;
    }
    Thanks in future.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Mastermind algorithm

    Do you have any specific java programming questions?

    Also it would be helpful if a simple, small, complete program were posted for testing.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Mastermind algorithm

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Mastermind comparision event help
    By predricted in forum New To Java
    Replies: 5
    Last Post: 01-15-2015, 07:20 PM
  2. Mastermind Java Code
    By TriSBR in forum New To Java
    Replies: 3
    Last Post: 11-03-2011, 07:40 PM
  3. problem mastermind
    By Alexander_003 in forum AWT / Swing
    Replies: 4
    Last Post: 03-16-2011, 05:08 PM
  4. Mastermind!
    By MishkaRX in forum New To Java
    Replies: 11
    Last Post: 12-14-2010, 01:39 PM
  5. MasterMind Problem!!
    By papinhio in forum New To Java
    Replies: 4
    Last Post: 07-09-2010, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •