Expand|Select|Wrap|Line Numbers
- public Integer[][][] populateLearning() throws FileNotFoundException
- {
- Integer[][][] learning2= new Integer[3][5][7];
- int pile=1;
- int stoneNumber=0;
- File f = new File("learningFile.txt");
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- String eachLine= "waiting to be filled";
- int a;
- int b;
- int c;
- while (eachLine != null)
- {
- for( a=0; a<3; a++)
- {
- for(b=0; b<5; b++)
- {
- for(c=0; c<7; c++)
- {
- try {
- eachLine = br.readLine();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- learning2[a][b][c]=Integer.parseInt(eachLine);
- }
- c=0;
- }
- b=0;
- }
- //Prints out each line in file
- }
- return learning2;
- }
Here is my code for refilling the array:
Expand|Select|Wrap|Line Numbers
- public void learn(Integer winner)
- {
- int adder=0;
- if(winner==0)
- {
- adder=1;
- }
- if(winner==0)
- {
- adder=-1;
- }
- for(int i=1; i<stones.size(); i=i+2)
- {
- Integer[] compsMove= stones.get(i);
- int a= compsMove[0];
- int b= compsMove[1];
- int c= compsMove[2];
- learning[a][b][c]=learning[a][b][c]+adder;
- }
- for(int i=2; i<stones.size(); i=i+2)
- {
- Integer[] compsMove= stones.get(i);
- int a= compsMove[0];
- int b= compsMove[1];
- int c= compsMove[2];
- learning[a][b][c]=learning[a][b][c]-adder;
- }
- overWriteLearning();
- }
- public void overWriteLearning()
- {
- FileOutputStream fout;
- try
- {
- // Open an output stream
- fout = new FileOutputStream ("learningFile");
- // Print a line of text
- int a;
- int b;
- int c;
- for( a=0; a<3; a++)
- {
- for(b=0; b<5; b++)
- {
- for(c=0; c<7; c++)
- {
- new PrintStream(fout).println (learning[a][b][c]);
- }
- c=0;
- }
- b=0;
- }
- //Prints out each line in file
- // Close our output stream
- fout.close();
- }
- // Catches any error conditions
- catch (IOException e)
- {
- System.err.println ("Unable to write to file");
- System.exit(-1);
- }
- }
Any suggestions on how I can get these to work?