Jump to content

danielbrthwt

Active Members
  • Posts

    62
  • Joined

  • Last visited

Everything posted by danielbrthwt

  1. I started by learning Python and from there it was really easy to pick up other languages like Java and C++, Python was great for me because it helped me understand some of the basic concepts of programming in a very understandable way
  2. The directory is D:, and i tried it the directory as \\.\D: because i read somewhere that that's how you are ment to access logical drives but that dident work ether it just said that the parameter was in correct for this line RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" ); [/CODE] i'm thinking that many the RandomFileAccess class cant access logical drives so ill have a look for a different class to read the data
  3. I thought that making some software that rips audio CD's and movies would be an interesting project, so to start i am trying to make something that takes the songs on a audio CD and saves to the hard rive as a WAV file, the only problem is that i cant seem to find much information on how to do this in Java and what i have found dosent, below is the code i have tried but when i run it i get access denied errors even when i run it as administrator import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.util.Scanner; public class learning { public static void main(String[] args) throws IOException { File cd = new File( "D:" ); RandomAccessFile rawAccess = new RandomAccessFile( cd, "r" ); byte[] content = new byte[2352]; rawAccess.readFully(content); System.out.println(content); } } [/CODE]. And the error i get is [CODE] Exception in thread "main" java.io.FileNotFoundException: D: (Access is denied) at java.io.RandomAccessFile.open(Native Method) at java.io.RandomAccessFile.<init>(Unknown Source) at learning.main(learning.java:13) [/CODE] Is there any way to read from the CD drive in Windows/Linux using java ?
  4. I am making a android game and at the moment i am working on a simple menu, this menu has 2 buttons one that generates a random map and lets you play it and one that takes you to a list of pre made levels. The problem is that if i press the random map button and run the game activity if i press the back button to return to the menu activity and try to play a random game again it crashes The following is the function that gets called when you press the random map button public void playRandom( View view ) { Intent intent = new Intent(this, CUBEGameActivity.class); intent.putExtra(EXTRA_MESSAGE, "RANDOM"); startActivity(intent); } [/CODE] how can i stop this, any help would be great Cheers Daniel
  5. I am trying to create a simple game for android, to start i am trying to make the square move down the y axis but the way i am doing it dosent move the square at all and i cant find any tutorials for GLES20 The on draw frame function in the render class updates the users position based on accleration dew to gravity, gets the transform matrix from the user class which is used to move the square down, then the program draws it. All that happens is that the square is drawn, no motion happens public void onDrawFrame(GL10 gl) { user.update(0.0, phy.AccelerationDewToGravity); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); // Re draws black background GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 12, user.SquareVB);//triangleVB); GLES20.glEnableVertexAttribArray(maPositionHandle); GLES20.glUniformMatrix4fv(maPositionHandle, 1, false, user.getTransformMatrix(), 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); } The update function in the player class is public void update(double vh, double vv) { Vh += vh; // Increase horrzontal Velosity Vv += vv; // Increase vertical velosity //Matrix.translateM(mMMatrix, 0, (int)Vh, (int)Vv, 0); Matrix.translateM(mMMatrix, 0, mMMatrix, 0, (float)Vh, (float)Vv, 0); }
  6. Thanks heaps it turns out it was the problem and now it works CHEERS !!
  7. Thanks i dident know that Open GL ES 1 was legacy i should probley use 2 before they conpleatly remove it
  8. Hey im trying to create a game for android but i am having some trouble with the Open GL im using, it works on the android emulator but not the actual phone, there both running the same OS which is 2.3.3. Has anyone else encountered these problems and how would you go about fixing them CODE LINKS : Player class ( One that contains the object coordinates ) - http://pastebin.com/mt0vxbCe OpenGLRender class - http://pastebin.com/YhbDbuX9 OpenGLSurfaceView - http://pastebin.com/4UejZgsm
  9. Thanks guys this will be great hopefully i can learn some things and understand the books online
  10. I am currently a collage student and I have been teaching my self programming for 2 years now and i have gotten quite interested in Artificial Intellengence but i cant find many books for learning this that are easy to understand is there anything anyone can recommend Cheers Daniel
  11. Me and a friend are thinking of making a 2D physics simulator for a school project but we have little knowledge of how to program GUIs with drawable objects does anyone have and good books or websites to learn from
  12. I was hoping to create a 14, 14 square and then make it so i can see through the square to what ever is underneath transparent
  13. I am designing a GUI in java and i need to make a transparent box that is resizeable and all i have found is how to make the whole frame transparent This is my GUI code import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class FloodItSolverGUI extends JFrame { private JButton scanButton; private JButton startButton; private JPanel window; private Board board = new Board(); private String[][] rawData; public FloodItSolverGUI( String[][] Data ) { super("Flood-It Solver"); setLayout( new FlowLayout() ); rawData = Data; scanButton = new JButton( "Scan Board" ); add( scanButton ); startButton = new JButton( "Start" ); add(startButton); ButtonHandler handler = new ButtonHandler(); scanButton.addActionListener(handler); startButton.addActionListener(handler); } private class ButtonHandler implements ActionListener { @Override public void actionPerformed(ActionEvent arg0) { if ( arg0.getActionCommand() == "Scan Board" ) { JOptionPane.showMessageDialog(FloodItSolverGUI.this, String.format("%s", "Sorry This Feture Is Not Available Yet")); } else if ( arg0.getActionCommand() == "Start" ) { String Result = ""; int[] results = board.runBot(rawData, 0); for ( int i = 0; i &lt; results.length; i++ ) { if ( results[i] != 0) Result += String.format("%d\n", results[i]); } JOptionPane.showMessageDialog(FloodItSolverGUI.this, Result); } } } }
  14. The problem was what you said but the clone() method didn't make a new/unconnected copy of my array of objects it just made a reference which is what it was doing in the first place so i made my own copy method which seemed to fix things public Square[][] copy( Square[][] board ) { Square[][] newBoard = new Square[14][14]; for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { int col = board[a][b].getNum(); int score = board[a][b].getScore(); int gId = board[a][b].getGroupid(); int[][] groupArray = board[a][b].getGroupArray(); newBoard[a][b] = new Square(); newBoard[a][b].tempChange(col); newBoard[a][b].setScore(score); newBoard[a][b].addToGroup(gId); newBoard[a][b].setGroupArray(groupArray); } } return newBoard; } P.S int0x80 thanks for the tip that will be helpful when posting thing in the future :D
  15. It could be i will have a look can you give me an example of what to look for, also i debugged my program and saw that even tho i was cloneing the array Square board = new Square[14][14]; Square newBoard; newBoard = board.clone(); newBoard2[0][0].tempChange(4); when i changed a value in newBoard it still changed in board
  16. I changed it to Square[][] newBoard = board.clone(); but it didn't change anything it still picks up values it shouldn't, i was researching and i found something that said that the clone() method doesn't work for multi dimensional arrays
  17. haha dident know that thanks, ill rember this no doubt ill make a simple mistake like this again
  18. ah okay so how do i duplicate the array object without getting these issues
  19. i know you don't want to spend money but if you do want to have a look at these ive been setting up some cheep web crawlers for about 300 NZD they have 64 bit processers so you could run proxmox and use full visualization there not the best computers but if you are looking for a cheep hack lab these could do Parts : AMD Sempron 145 2.8 GHz - http://www.ascent.co.nz/productspecification.aspx?ItemID=401348 Kingston HyperX Blu KHX1333C9D3B1K2 - http://www.ascent.co.nz/productspecification.aspx?ItemID=9390314 Cooler Master Elite Power - http://www.ascent.co.nz/productspecification.aspx?ItemID=382473
  20. Some of you might know this program from a recent post of mine, i am writing a flood-it solver and it is nearly finished apart from that my function that thinks ahead dosent work, the problem is that somehow my main board ( globalBoard ) somehow picks up values from the temp board in the thinkAhead function called ( newBoard ) i have posted the code sorry its a bit long the thinkAhead function is close to the bottom public class Board { static int totalRemoved = 0; static int bestmove = 0; static int[] moveScores = new int[3]; static int[] finalMoves = new int[25]; static int elimColour = 0; static int highestGroup = 0; static int[][] blacklist = new int[14][14]; static int[][] tempblacklist = new int[14][14]; static int curGroup = 0; static int isGroup = 0; static int[][] group; static int numOfSquares = 0; static int totalPink = 0; static int totalPurple = 0; static int totalYellow = 0; static int totalRed = 0; static int totalBlue = 0; static int totalGreen = 0; int finished = 0; int removeColour = 0; //public static Square[][] globalBoard; static int[] pubAround; static int up; static int down; static int left; static int right; static int col; static int gid; static int pinkC = 0; static int pinkM = 0; static int[][] pinkLoc; static int purpleC; static int purpleM; static int[][] purpleLoc; static int yellowC = 0; static int yellowM = 0; static int[][] yellowLoc; static int redC = 0; static int redM = 0; static int[][] redLoc; static int blueC = 0; static int blueM = 0; static int[][] blueLoc; static int greenC = 0; static int greenM = 0; static int[][] greenLoc; static float pinkS; static float purpleS; static float yellowS; static float redS; static float blueS; static float greenS; public Board() { /*System.out.println("*TEST"); for ( int a = 0; a &lt; 14; a++ ) { for ( int b = 0; b &lt; 14; b++ ) { board[a][b] = new Square(); } }*/ } public void collectColours( Square[][] board ) { for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { if ( board[a][b].getGroupid() != 0 ) { if ( board[a][b].getNum() == 1 ) totalPink++; if ( board[a][b].getNum() == 2 ) totalPurple++; if ( board[a][b].getNum() == 3 ) totalYellow++; if ( board[a][b].getNum() == 4 ) totalRed++; if ( board[a][b].getNum() == 5 ) totalBlue++; if ( board[a][b].getNum() == 6 ) totalGreen++; } } } } public int checkStatus( Square[][] board ) { if ( board[0][0].getGroupid() != -1 ) { if ( board[0][0].getGroupArray().length == 14*14 ) return 1; } return 0; /* int startCol = board[0][0].getNum(); for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { if ( board[a][b].getNum() != startCol ) return 0; } } return 1; */ } public static int[][] extendArray( int[][] array ) { int[][] newArray = new int[array.length+1][2]; for ( int i = 0; i &lt; array.length; i++ ) { newArray[i] = array[i]; } return newArray; } public static int[] extendArray( int[] array ) { int[] newArray = new int[array.length+1]; for ( int i = 0; i &lt; array.length; i++ ) { newArray[i] = array[i]; } return newArray; } public static void printBoardNum( Square[][] board) { System.out.println("--------------------------------------------------------"); for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { System.out.printf("| %d ", board[a][b].getNum()); } System.out.println("|"); System.out.println("--------------------------------------------------------"); } } public static void clearVariables() { blacklist = new int[14][14]; numOfSquares = 0; curGroup = 0; elimColour = 0; up = 0; down = 0; left = 0; right = 0; col = 0; gid = 0; pinkS = 0; purpleS = 0; yellowS = 0; redS = 0; blueS = 0; greenS = 0; totalPink = 0; totalPurple = 0; totalYellow = 0; totalRed = 0; totalBlue = 0; totalGreen = 0; pinkC = 0; pinkM = 0; pinkLoc = new int[1][2]; purpleC = 0; purpleM = 0; purpleLoc = new int[1][2]; yellowC = 0; yellowM = 0; yellowLoc = new int[1][2]; redC = 0; redM = 0; redLoc = new int[1][2]; blueC = 0; blueM = 0; blueLoc = new int[1][2]; greenC = 0; greenM = 0; greenLoc = new int[1][2]; } public Square[][] processNewBoard( Square[][] board, String[][] colours ) { for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++) { board[a][b] = new Square(); board[a][b].setState(colours[a][b]); } } return board; } public static void printBoardGroupIds( Square[][] board ) { System.out.println("--------------------------------------------------------"); for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++) { System.out.printf("| %d ", board[a][b].getGroupid()); } System.out.println("|"); System.out.println("--------------------------------------------------------"); } } public static Square[][] resetBoard( Square[][] board ) { for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { board[a][b].addToGroup(-1); board[a][b].setScore(0); board[a][b].setGroupArray(new int[0][2]); } } return board; } public int[][] nextToClear( Square[][] board ) { int[][] startingGroup; int startingGroupId; int[][] nextToClear; int[][] blacklist; startingGroup = board[0][0].getGroupArray(); startingGroupId = board[0][0].getGroupid(); nextToClear = new int[0][2]; blacklist = new int[14][14]; if ( startingGroupId != -1 ) { for ( int i = 0; i &lt; startingGroup.length; i++ ) { int a = startingGroup[i][0]; int b = startingGroup[i][1]; //nextToClear = extendArray(nextToClear); blacklist[a][b] = 1; if ( a &gt; 0 &amp;&amp; board[a-1][b].getGroupid() != startingGroupId &amp;&amp; blacklist[a-1][b] != 1 ) { nextToClear = extendArray(nextToClear); nextToClear[nextToClear.length-1][0] = a-1; nextToClear[nextToClear.length-1][1] = b; blacklist[a-1][b] = 1; } if ( a &lt; 13 &amp;&amp; board[a+1][b].getGroupid() != startingGroupId &amp;&amp; a &gt; 0 &amp;&amp; blacklist[a+1][b] != 1 ) { nextToClear = extendArray(nextToClear); nextToClear[nextToClear.length-1][0] = a+1; nextToClear[nextToClear.length-1][1] = b; blacklist[a-1][b] = 1; } if ( b &gt; 0 &amp;&amp; board[a][b-1].getGroupid() != startingGroupId &amp;&amp; blacklist[a][b-1] != 1 ) { nextToClear = extendArray(nextToClear); nextToClear[nextToClear.length-1][0] = a; nextToClear[nextToClear.length-1][1] = b-1; blacklist[a][b-1] = 1; } if ( b &lt; 13 &amp;&amp; board[a][b+1].getGroupid() != startingGroupId &amp;&amp; blacklist[a][b+1] != 1 ) { nextToClear = extendArray(nextToClear); nextToClear[nextToClear.length-1][0] = a; nextToClear[nextToClear.length-1][1] = b+1; blacklist[a][b+1] = 1; } } } else { nextToClear = extendArray(nextToClear); nextToClear[0][0] = 0; nextToClear[0][1] = 1; nextToClear = extendArray(nextToClear); nextToClear[1][0] = 1; nextToClear[0][1] = 0; } return nextToClear; } public Square[][] scoreSquare( Square[][] board, int[] touchingGroupsBlackList, int a, int b ) { int[][] squaresGroup = new int[1][2]; int ownid = board[a][b].getGroupid(); int multi = 0; if ( ownid == -1 ) { if ( a &gt; 0 &amp;&amp; board[a-1][b].getGroupid() != 0 &amp;&amp; board[a-1][b].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a-1][b].getGroupid()] != -1 &amp;&amp; board[a-1][b].getGroupid() != ownid ) multi += board[a-1][b].getGroupArray().length; if ( a &lt; 13 &amp;&amp; board[a+1][b].getGroupid() != 0 &amp;&amp; board[a+1][b].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a+1][b].getGroupid()] != -1 &amp;&amp; board[a+1][b].getGroupid() != ownid ) multi += board[a+1][b].getGroupArray().length; if ( b &gt; 0 &amp;&amp; board[a][b-1].getGroupid() != 0 &amp;&amp; board[a][b-1].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a][b-1].getGroupid()] != -1 &amp;&amp; board[a][b-1].getGroupid() != ownid ) multi += board[a][b-1].getGroupArray().length; if ( b &lt; 13 &amp;&amp; board[a][b+1].getGroupid() != 0 &amp;&amp; board[a][b+1].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a][b+1].getGroupid()] != -1 &amp;&amp; board[a][b+1].getGroupid() != ownid ) multi += board[a][b+1].getGroupArray().length; } else if ( ownid != -1 ) { squaresGroup = board[a][b].getGroupArray(); for ( int i = 0; i &lt; squaresGroup.length; i++ ) { a = squaresGroup[i][0]; b = squaresGroup[i][1]; if ( a &gt; 0 &amp;&amp; board[a-1][b].getGroupid() != 0 &amp;&amp; board[a-1][b].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a-1][b].getGroupid()] != -1 &amp;&amp; board[a-1][b].getGroupid() != ownid ) multi += board[a-1][b].getGroupArray().length; if ( a &lt; 13 &amp;&amp; board[a+1][b].getGroupid() != 0 &amp;&amp; board[a+1][b].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a+1][b].getGroupid()] != -1 &amp;&amp; board[a+1][b].getGroupid() != ownid ) multi += board[a+1][b].getGroupArray().length; if ( b &gt; 0 &amp;&amp; board[a][b-1].getGroupid() != 0 &amp;&amp; board[a][b-1].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a][b-1].getGroupid()] != -1 &amp;&amp; board[a][b-1].getGroupid() != ownid ) multi += board[a][b-1].getGroupArray().length; if ( b &lt; 13 &amp;&amp; board[a][b+1].getGroupid() != 0 &amp;&amp; board[a][b+1].getGroupid() != -1 &amp;&amp; touchingGroupsBlackList[board[a][b+1].getGroupid()] != -1 &amp;&amp; board[a][b+1].getGroupid() != ownid ) multi += board[a][b+1].getGroupArray().length; } } else multi = 1; board[a][b].setScore(multi); return board; } public Square[][] score( Square[][] board ) { int startingGroup; int[][] nextToClear; int[] touchingGroupsBlackList; int[] touchingGroups; int[] usedGroups; startingGroup = board[0][0].getGroupid(); nextToClear = nextToClear(board); touchingGroupsBlackList = new int[highestGroup+1]; touchingGroups = new int[0]; usedGroups = new int[highestGroup+1]; for ( int i = 0; i &lt; nextToClear.length; i++ ) { int gId = board[nextToClear[i][0]][nextToClear[i][1]].getGroupid(); if ( gId != -1 &amp;&amp; touchingGroupsBlackList[gId] != 1 &amp;&amp; gId != startingGroup &amp;&amp; gId != 0 ) { //touchingGroups = extendArray(touchingGroups); //touchingGroups[touchingGroups.length-1] = gId; touchingGroupsBlackList[gId] = 1; } } for ( int i = 0; i &lt; nextToClear.length; i++ ) { int a; int b; int col; int totalSqu; a = nextToClear[i][0]; b = nextToClear[i][1]; col = board[a][b].getNum(); totalSqu = 1; if ( board[a][b].getGroupid() != -1 &amp;&amp; col != board[0][0].getNum() &amp;&amp; usedGroups[board[a][b].getGroupid()+1] != 1 ) { if ( board[a][b].getGroupid() != -1 ) totalSqu = board[a][b].getGroupArray().length; board = scoreSquare( board, touchingGroupsBlackList, a, B); usedGroups[board[a][b].getGroupid()+1] = 1; if ( col == 1 ) { pinkS += totalSqu * board[a][b].getScore(); pinkC += totalSqu; } if ( col == 2 ) { purpleS += totalSqu * board[a][b].getScore(); purpleC += totalSqu; } if ( col == 3 ) { yellowS += totalSqu * board[a][b].getScore(); yellowC += totalSqu; } if ( col == 4 ) { redS += totalSqu * board[a][b].getScore(); redC += totalSqu; } if ( col == 5 ) { blueS += totalSqu * board[a][b].getScore(); blueC += totalSqu; } if ( col == 6 ) { greenS += totalSqu * board[a][b].getScore(); greenC += totalSqu; } } } /*for ( int i = 0; i &lt; nextToClear.length; i++ ) { int a = nextToClear[i][0]; int b = nextToClear[i][1]; int col = board[a][b].getNum(); if ( col == 1 ) pinkC += totalSqu; if ( col == 2 ) purpleC += totalSqu; if ( col == 3 ) yellowC += totalSqu; if ( col == 4 ) redC += totalSqu; if ( col == 5 ) blueC += totalSqu; if ( col == 6 ) greenC += totalSqu; int score = scoreSquare(board, a, B); board[a][b].setScore(score); }*/ return board; } public int[] chooesMoves( int choices ) { int[] moves = new int[0]; int[] options = new int[6]; float totalScore; int totalCount; int optionsLeft; totalScore = pinkS + purpleS + yellowS + redS + blueS + greenS; totalCount = pinkC + purpleC + yellowC + redC + blueC + greenC; optionsLeft = totalCount; for ( int i = 0; i &lt; choices; i++ ) { if ( totalPink != 0 &amp;&amp; pinkC == totalPink &amp;&amp; options[0] != 1) { moves = extendArray(moves); moves[moves.length-1] = 1; options[0] = 1; removeColour = 1; } else if ( totalPurple != 0 &amp;&amp; purpleC == totalPurple &amp;&amp; options[1] != 1) { moves = extendArray(moves); moves[moves.length-1] = 2; options[1] = 1; removeColour = 1; } else if ( totalYellow != 0 &amp;&amp; yellowC == totalYellow &amp;&amp; options[2] != 1) { moves = extendArray(moves); moves[moves.length-1] = 3; options[2] = 1; removeColour = 1; } else if ( totalRed != 0 &amp;&amp; redC == totalRed &amp;&amp; options[3] != 1) { moves = extendArray(moves); moves[moves.length-1] = 4; options[3] = 1; removeColour = 1; } else if ( totalBlue != 0 &amp;&amp; blueC == totalBlue &amp;&amp; options[4] != 1) { moves = extendArray(moves); moves[moves.length-1] = 5; options[4] = 1; removeColour = 1; } else if ( totalGreen != 0 &amp;&amp; greenC == totalGreen &amp;&amp; options[5] != 1) { moves = extendArray(moves); moves[moves.length-1] = 6; options[5] = 1; removeColour = 1; } else if ( pinkS * 5 &gt; totalScore-pinkS &amp;&amp; options[0] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 1; options[0] = 1; optionsLeft -= pinkC; } else if ( purpleS * 5 &gt; totalScore-purpleS &amp;&amp; options[1] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 2; options[1] = 1; optionsLeft -= purpleC; } else if ( yellowS * 5 &gt; totalScore-yellowS &amp;&amp; options[2] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 3; options[2] = 1; optionsLeft -= yellowC; } else if ( redS * 5 &gt; totalScore-redS &amp;&amp; options[3] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 4; options[3] = 1; optionsLeft -= redC; } else if ( blueS * 5 &gt; totalScore-blueS &amp;&amp; options[4] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 5; options[4] = 1; optionsLeft -= blueC; } else if ( greenS * 5 &gt; totalScore-greenS &amp;&amp; options[5] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 6; options[5] = 1; optionsLeft -= greenC; } if ( pinkC * 5 &gt; totalCount-pinkC &amp;&amp; options[0] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 1; options[0] = 1; optionsLeft -= pinkC; } else if ( purpleC * 5 &gt; totalCount-purpleC &amp;&amp; options[1] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 2; options[1] = 1; optionsLeft -= purpleC; } else if ( yellowC * 5 &gt; totalCount-yellowC &amp;&amp; options[2] != 1) { moves = extendArray(moves); moves[moves.length-1] = 3; options[2] = 1; optionsLeft -= yellowC; } else if ( redC * 5 &gt; totalCount-redC &amp;&amp; options[3] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 4; options[3] = 1; optionsLeft -= redC; } else if ( blueC * 5 &gt; totalCount-blueC &amp;&amp; options[4] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 5; options[4] = 1; optionsLeft -= blueC; } else if ( greenC * 5 &gt; totalCount-greenC &amp;&amp; options[5] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 6; options[5] = 1; optionsLeft -= greenC; } /*else { moves = extendArray(moves); moves[i] = 0; }*/ else if ( options[0] != 1 &amp;&amp; pinkC * optionsLeft &gt; totalCount-pinkC ) { moves = extendArray(moves); moves[moves.length-1] = 1; options[0] = 1; optionsLeft--; totalCount -= pinkC; } else if ( options[1] != 1 &amp;&amp; purpleC * optionsLeft &gt; totalCount-purpleC) { moves = extendArray(moves); moves[moves.length-1] = 2; options[1] = 1; optionsLeft--; totalCount -= purpleC; } else if ( options[2] != 1 &amp;&amp; yellowC * optionsLeft &gt; totalCount-yellowC ) { moves = extendArray(moves); moves[moves.length-1] = 3; options[2] = 1; optionsLeft--; totalCount -= yellowC; } else if ( options[3] != 1 &amp;&amp; redC * optionsLeft &gt; totalCount-redC ) { moves = extendArray(moves); moves[moves.length-1] = 4; options[3] = 1; optionsLeft--; totalCount -= redC; } else if ( options[4] != 1 &amp;&amp; blueC * optionsLeft &gt; totalCount-blueC ) { moves = extendArray(moves); moves[moves.length-1] = 5; options[4] = 1; optionsLeft--; totalCount -= blueC; } else if ( options[5] != 1 &amp;&amp; greenC * optionsLeft &gt; totalCount-greenC ) { moves = extendArray(moves); moves[moves.length-1] = 6; options[5] = 1; optionsLeft--; totalCount -= greenC; } } /*int[] moves = new int[0]; int[] options = new int[6]; int totalSquares = pinkC + purpleC + yellowC + redC + blueC + greenC; for ( int i = 0; i &lt; choices; i++ ) { if ( pinkC * 5 &gt; totalSquares-pinkC &amp;&amp; options[0] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 1; options[0] = 1; } else if ( purpleC * 5 &gt; totalSquares-purpleC &amp;&amp; options[1] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 2; options[1] = 1; } else if ( yellowC * 5 &gt; totalSquares-yellowC &amp;&amp; options[2] != 1) { moves = extendArray(moves); moves[moves.length-1] = 3; options[2] = 1; } else if ( redC * 5 &gt; totalSquares-redC &amp;&amp; options[3] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 4; options[3] = 1; } else if ( blueC * 5 &gt; totalSquares-blueC &amp;&amp; options[4] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 5; options[4] = 1; } else if ( greenC * 5 &gt; totalSquares-greenC &amp;&amp; options[5] != 1 ) { moves = extendArray(moves); moves[moves.length-1] = 6; options[5] = 1; } else { moves = extendArray(moves); moves[i] = 0; } }*/ return moves; } public static Square[][] findGroups( Square[][] board ) { highestGroup = 0; for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { board[a][b].setGroupArray(null); board[a][b].addToGroup(-1); } } group = null; int stop = 0; int stop2 = stop; for ( int a = 0; a &lt; board.length; a++ ) { for ( int b = 0; b &lt; board[a].length; b++ ) { group = new int[1][2]; group[numOfSquares][0] = a; group[numOfSquares][1] = b; numOfSquares++; col = 0; col = board[a][b].getNum(); blacklist[a][b] = 1; isGroup = findAround(board, a, b, col); if ( isGroup == 1 &amp;&amp; board[a][b].getGroupid() == -1 ) { board[a][b].addToGroup(curGroup); for ( int i = 0; i &lt; group.length; i++ ) { board[group[i][0]][group[i][1]].setGroupArray(group); blacklist[(group[i][0])][group[i][1]] = 1; } curGroup++; highestGroup++; numOfSquares = 0; } numOfSquares = 0; tempblacklist = new int[14][14]; } } blacklist = new int[14][14]; tempblacklist = new int[14][14]; curGroup = 0; isGroup = 0; group = new int[1][2]; numOfSquares = 0; return board; } private static int findAround( Square[][] board, int a, int b, int col) { int[] around = new int[4]; int inGroup = 0; if ( a &gt; 0 ) around[0] = board[a-1][b].getNum(); else around[0] = 0; if ( a &lt; 13 ) around[1] = board[a+1][b].getNum(); else around[1] = 0; if ( b &gt; 0 ) around[2] = board[a][b-1].getNum(); else around[2] = 0; if ( b &lt; 13 ) around[3] = board[a][b+1].getNum(); else around[3] = 0; if ( /*a &gt; 0 &amp;&amp;*/ around[0] == col &amp;&amp; tempblacklist[a-1][b] != 1 &amp;&amp; blacklist[a-1][b] != 1 ) { group = extendArray(group); group[numOfSquares][0] = a-1; group[numOfSquares][1] = b; numOfSquares++; tempblacklist[a-1][b] = 1; board[a-1][b].addToGroup(curGroup); inGroup = 1; findAround( board, a-1, b, col ); } if ( /*a &lt; 13 &amp;&amp;*/ around[1] == col &amp;&amp; tempblacklist[a+1][b] != 1 &amp;&amp; blacklist[a+1][b] != 1) { group = extendArray(group); group[numOfSquares][0] = a+1; group[numOfSquares][1] = b; numOfSquares++; tempblacklist[a+1][b] = 1; board[a+1][b].addToGroup(curGroup); inGroup = 1; findAround( board, a+1, b, col ); } if ( /*b &gt; 0 &amp;&amp;*/ around[2] == col &amp;&amp; tempblacklist[a][b-1] != 1 &amp;&amp; blacklist[a][b-1] != 1) { group = extendArray(group); group[numOfSquares][0] = a; group[numOfSquares][1] = b-1; numOfSquares++; tempblacklist[a][b-1] = 1; board[a][b-1].addToGroup(curGroup); inGroup = 1; findAround( board, a, b-1, col ); } if ( /*b &lt; 13 &amp;&amp;*/ around[3] == col &amp;&amp; tempblacklist[a][b+1] != 1 &amp;&amp; blacklist[a][b+1] != 1) { group = extendArray(group); group[numOfSquares][0] = a; group[numOfSquares][1] = b+1; numOfSquares++; tempblacklist[a][b+1] = 1; board[a][b+1].addToGroup(curGroup); inGroup = 1; findAround( board, a, b+1, col ); } pubAround = around; return inGroup; } public int thinkFoward( Square[][] board, int[] moves, int amMoves, int stepsAhead, int depth ) { int move = 0; int oldLen = 0; int tmpMove; int status; int[] newMoves; int[] moveScores = new int[moves.length]; Square[][] newBoard = new Square[14][14]; if ( stepsAhead != 0 ) { for ( int i = 0; i &lt; moves.length; i++ ) { newBoard = board; status = checkStatus(newBoard); if ( status == 0 &amp;&amp; moves[i] != 0 ) { //oldLen = newBoard[0][0].getGroupArray().length; tmpMove = moves[i]; newBoard = makeMove( newBoard, tmpMove ); //printBoardGroupIds(newBoard); //newBoard = resetBoard(newBoard); newBoard = findGroups(newBoard); //printBoardGroupIds(newBoard); finished = checkStatus(newBoard); collectColours(newBoard); //System.out.println("*"); //printBoardNum(newBoard); totalRemoved += (14*14)-((14*14)-newBoard[0][0].getGroupArray().length); //totalRemoved += newBoard[0][0].getGroupArray().length-oldLen; //int tempLen = newBoard[0][0].getGroupArray().length; //int grpCheck = newBoard[2][1].getGroupid(); //totalRemoved = newBoard[0][0].getGroupArray().length; if ( finished == 1 ) { finished = 0; if ( depth != 0 ) return 0; else return moves[i]; } if ( removeColour == 1 ) { removeColour = 0; if ( depth != 0 ) return 0; else return moves[i]; } clearVariables(); newBoard = score(newBoard); newMoves = chooesMoves( amMoves ); thinkFoward( newBoard, newMoves, amMoves, stepsAhead-1, depth+1 ); /*newBoard = resetBoard(newBoard); status = checkStatus(newBoard); newBoard = findGroups(newBoard); score(newBoard); int[] newMoves = chooesMoves( 3 ); moves[i] = thinkFoward( board, newMoves, stepsAhead-1, depth+1 ); totalRemoved += (14*14)-((14*14)-newBoard[0][0].getGroupArray().length);*/ } /*else { return 0; }*/ if ( depth == 0) { //test = move; moveScores[i] = totalRemoved; //test = move; totalRemoved = 0; } } if ( depth == 0 ) { int total = 0; for ( int i = 0; i &lt; moves.length; i++ ) { //test = move; total += moveScores[i]; } if ( moveScores[0] == (int) total/3 ) { for ( int i = 0; i &lt; moves.length; i++ ) { //test = move; if ( moveScores[i] * moveScores.length-1 &gt; total - moveScores[i] ) { move = moves[i]; } //test = move; } } else move = moves[0]; /* int a = moveScores[0]; int b = moveScores[1]; int c = moveScores[2]; if ( a * 2 &gt; b+c ) move = moves[0]; if ( b * 2 &gt; a+c ) move = moves[1]; if ( c * 2 &gt; a+b ) move = moves[2]; */ } } return move; } public Square[][] makeMove( Square[][] board, int move ) { if ( board[0][0].getGroupid() != -1 ) { int[][] toChange = board[0][0].getGroupArray(); for ( int i = 0; i &lt; toChange.length; i++ ) { board[toChange[i][0]][toChange[i][1]].tempChange(move); } } else { board[0][0].tempChange(move); } return board; } public int[] runBot( String[][] rawData, int test ) { Square[][] globalBoard = new Square[14][14]; int[] allMoves = new int[0]; int [] moves = {1,2,3,4,5,6}; int move = 0; int i = 0; int status = 0; globalBoard = processNewBoard( globalBoard, rawData ); while ( status == 0 /*&amp;&amp; &lt; 25*/ ) { printBoardNum(globalBoard); globalBoard = findGroups( globalBoard ); int[][] stGroup = globalBoard[0][0].getGroupArray(); //printBoardGroupIds(globalBoard); collectColours(globalBoard); globalBoard = score( globalBoard ); moves = chooesMoves( 3 ); move = thinkFoward( globalBoard, moves, 3, 1, 0); if ( move != 0 ) globalBoard = makeMove( globalBoard, move ); allMoves = extendArray(allMoves); allMoves[allMoves.length-1] = move; i++; status = checkStatus(globalBoard); globalBoard = resetBoard(globalBoard); clearVariables(); } return allMoves; } }
  21. Thank im terrable at researching i never know what to search haha you have been a great help
  22. Thanks alot i havent worked on android apps before ether so this has been a huge help
  23. I am trying to write an android app i dont have much experence but i want to beable to crop a photo and then detect colous as sertian locations in the photo
  24. Thank you so much that fixed the problem i was having
  25. i used the folowing statments to debug my program when i was trying to find the problem : //startingGroup = board[0].getGroupArray(0); //startingGroup = reset; ( had a breakpoint on this line to view the startingGroup variable before its reset ) and the only line that changed the variable once it was set was group[numOfSquares][1] = b; Is this what you ment or did you mean something else
×
×
  • Create New...