Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 5th, 2005, 5:00 PM   #1
pascal_c
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 pascal_c is on a distinguished road
Hi, im new into java and i need help () i know it sounds a little arrogant for asking but i try anyway




I have made a program called "mastermind" what now must be done is making a codebreaker program that automaticly "gueses" the random numbers

e.g:


there are 6 colors and 4 pions so ther are 1296 combinations

Lets say i use this number --> 1236 this means:


1 = color red
2 = color black
3 = color cyan
6 = color red


The computer is "guessing" the first number and if it maches it shows up and goes to the next number.

I don't know how to do this.


if only someone could help me i would really be gratefull
ty

Pascal.


ps i have experience in programming with c & assembler but new with java.
I know this uses "codebreaker" 2d array's
pascal_c is offline   Reply With Quote
Old Jan 5th, 2005, 8:28 PM   #2
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
I took an Artificial Intelligence class last semester, and our midterm project was a mastermind codebreaker. If you don't want to brute force the guesses (i.e. start at 0000 and search untill 9999, incrementing by 1 every time) you'll have to implement some sort of knowledge base of rules, and also apply logic rules that use the outcome of previous guesses to narrow down the search space. I'd suggest searching google for "Mastermind algorithm" it might give you a little more information. PM me, or reply if you have any more specific questions.
-JSS
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 6th, 2005, 7:20 AM   #3
pascal_c
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 pascal_c is on a distinguished road
Great to hear someone with experience can you help me becasue i know what i must do but i dont know how to implement it.


By chance.. do you have source code so i can take a look? don;t worry im not a "copy paste" guy i just need to know what i must do to make it work. and im new with java so i dont really know manythings.


thank you for your replay & help.
pascal_c is offline   Reply With Quote
Old Jan 6th, 2005, 8:58 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
are ya'll in the same damn class because we've have had three "mastermind" posts in the last 48 hours.

:ph34r:
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Jan 6th, 2005, 9:21 AM   #5
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
I didn't actually write the code, I just wrote a paper on the implementation. I don't have a soft copy of it available, sorry. Basically what you want to do, is make 4 arrays of possible numbers in possible locations, then based on the guesses you can cross off numbers from certain locations, and create a tree out of it, so you can backtrack in case you made a wrong assumption. Is this assignment for a class? In that case, what class?
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 6th, 2005, 6:39 PM   #6
pascal_c
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 pascal_c is on a distinguished road
Actually yes, its an assignment for school



i want to know how to make the codebreaker thing i know its with a 2d array

But i dont know howto aply it on my on excisting code breaker program can someone help me ?
pascal_c is offline   Reply With Quote
Old Jan 6th, 2005, 7:20 PM   #7
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
what do you mean 'it's with a 2d array' there are many ways of solving this problem. I know of one, If you have another way in mind, I cannot help you with that. Why don't you email your instructor for help, or a TA or so.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 7th, 2005, 8:59 AM   #8
pascal_c
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 pascal_c is on a distinguished road
This is my code:

ArrayList test = new ArrayList ();

int code[] = new int[4];

for (int i = 0; i < 1296; ++i)
{
code[3] = code[3] + 1;
for (int c = 3; c >= 0; ++c)
{
if (code[c] > 4)
{
code[c] = 1;
code[c - 1] = code[c - 1] + 1;
}
}
test.add(code);

System.out.println(" " + test);



Now all i want is this input a number and the forloop checks if the number is equal and then go to the second number then 3rd/4th and then stop. I know you guys call me "noob" but i just started java =)
pascal_c is offline   Reply With Quote
Old Jan 7th, 2005, 9:38 AM   #9
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
ok, so you want to brute force the search. What is code[] initialized at? I assume 1234? So you're gonna want to search all numbers between 1234 and 6543 that don't have duplicate digits in it. I recommend not making a loop that counts how many possibilities there are, but a loop that starts from the min and the max values of each index.
ex.
for(int i=1;i<=6;i++){
 for(int j=1;j<=6;j++){
  for(int h=1;h<=6;h++){
   for(int k=1;k<=6;k++){
    code[0] = i;
    code[1] = j;
    code[2] = h;
    code[3] = k;
   }
  }
 }
}
now this will iterate through every number between 1111 and 6666, but it should get you on the right track.
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 8th, 2005, 8:14 AM   #10
pascal_c
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 pascal_c is on a distinguished road
Hi, this is my code:

import java.util.ArrayList;


public class codebreaker
{
 public static void main(String[] args)
 {
	//	int[][] code = new int [1296] [4];
 ArrayList test = new ArrayList ();
 ArrayList pion = new ArrayList ();
 ArrayList color = new ArrayList ();


  	pion.add(0,"pion 1");
  	pion.add(1,"pion 2");
  	pion.add(2,"pion 3");
  	pion.add(3,"pion 4");

  	color.add(0,"color White");
  	color.add(1,"color Black");
  	color.add(2,"color Brown");
  	color.add(3,"color Cyan");
  	color.add(4,"color Yellow");
  	color.add(5,"color Red");


 System.out.println(" " + pion.get(0) +" " + color.get(1) );
 System.out.println(" " + pion.get(1) +" " + color.get(2) );
 System.out.println(" " + pion.get(2) +" " + color.get(3) );
 System.out.println(" " + pion.get(3) +" " + color.get(5) + "\n" + "\n");


 System.out.println("show all pion and color" + "\n" + pion + "\n"+ color + "\n");


  if (pion.isEmpty()) {
  System.out.println("Empty");
 } else
 	{
   System.out.println("End");
 	}
 }
	}


How can i use your for loop to "search" for the correct number. What my program now does is just getting the pions and color's but i want it dynamicly like your forloop
and i also dont know howto input a number for a computer to guess.


ty for your time.
pascal_c is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC