Created
March 28, 2014 04:09
-
-
Save maxzhang000/9825188 to your computer and use it in GitHub Desktop.
Revisions
-
maxzhang000 created this gist
Mar 28, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,149 @@ package player; public abstract class MyBoard { /** * @param args */ private Piece[][] pieces = new Piece[8][8]; public boolean isValidMove(Move m){ return false; } public boolean checkInvalidMove(Move m, int playerColor){ if (m.moveKind == 0){ return false; }else if (m.moveKind == 1){ if (numPieces(playerColor) == 10){ return true; }else{ if (isOccupied(m.x1,m.y1)||isInOppGoalOrCorner(m.x1,m.y1,playerColor)||wouldMakeTrio(m.x1,m.y1,playerColor)){ return true; } } }else if (m.moveKind == 2){ if (isOccupied(m.x1,m.y1)||isInOppGoalOrCorner(m.x1,m.y1,playerColor)||wouldMakeTrio(m.x1,m.y1,playerColor)){ return true; } } else { return false; } } private boolean wouldMakeTrio(int x,int y,int playerColor){ if (adjPieces(x,y,playerColor)<2){ return false; }else{ return true; } } private boolean isOccupied(int x,int y){ if (hasPiece(x,y)==1){ return true; }else{ return false; } } private int numPieces(){ int numPieces = 0; for (int x = 0; x<8 ;x++){ for (int y = 0; y<8 ;y++){ if (! pieces[x][y] instanceof NullPiece){ numPieces++; } } } return numPieces; } private int numPieces(int playerColor){ int numPieces = 0; for (int x = 0; x<8 ;x++){ for (int y = 0; y<8 ;y++){ if (! pieces[x][y] instanceof NullPiece && pieces[x][y].getColor() == playerColor){ numPieces++; } } } return numPieces; } private boolean isInOppGoalOrCorner(int x,int y,int playerColor){//black is top to bottom white is side to side if (playerColor == 0){ if (y==0 || y==7){ return true; }else{ return false; } }else{ if (x==0 || x==7){ return true; }else{ return false; } } } private int hasPiece(int x,int y){ if (pieces[x][y] instanceof NullPiece){ return 0; }else { return 1; } } private int hasPiece(int x,int y,int playerColor){ if (pieces[x][y] instanceof NullPiece){ return 0; }else if (pieces[x][y].getColor() == playerColor){ return 1; }else{ return 0; } } private int adjPieces(int x,int y,int playerColor){ if (x == 0){ if (y == 0){ return hasPiece(x+1,y,playerColor)+hasPiece(x,y+1,playerColor)+hasPiece(x+1,y+1,playerColor); }else if (y>0 && y<7){ return hasPiece(x+1,y,playerColor)+hasPiece(x,y+1,playerColor)+hasPiece(x+1,y+1,playerColor)+hasPiece(x,y-1,playerColor)+hasPiece(x+1,y-1,playerColor); }else{ return hasPiece(x+1,y,playerColor)+hasPiece(x,y-1,playerColor)+hasPiece(x+1,y-1,playerColor); } }else if (x>0 && x<7){ if (y == 0){ return hasPiece(x-1,y+1,playerColor)+hasPiece(x-1,y,playerColor)+ hasPiece(x,y+1,playerColor)+hasPiece(x,y,playerColor)+ hasPiece(x+1,y+1,playerColor)+hasPiece(x+1,y,playerColor); }else if (y>0 && y<7){ return hasPiece(x-1,y+1,playerColor)+hasPiece(x-1,y,playerColor)+hasPiece(x-1,y-1,playerColor)+ hasPiece(x,y+1,playerColor)+hasPiece(x,y,playerColor)+hasPiece(x,y-1,playerColor)+ hasPiece(x+1,y+1,playerColor)+hasPiece(x+1,y,playerColor)+hasPiece(x+1,y-1,playerColor); }else{ return hasPiece(x-1,y,playerColor)+hasPiece(x-1,y-1,playerColor)+ hasPiece(x,y,playerColor)+hasPiece(x,y-1,playerColor)+ hasPiece(x+1,y,playerColor)+hasPiece(x+1,y-1,playerColor); } }else{ if (y == 0){ return hasPiece(x-1,y,playerColor)+hasPiece(x,y+1,playerColor)+hasPiece(x-1,y+1,playerColor); }else if (y>0 && y<7){ return hasPiece(x-1,y,playerColor)+hasPiece(x,y+1,playerColor)+hasPiece(x-1,y+1,playerColor)+hasPiece(x,y-1,playerColor)+hasPiece(x-1,y-1,playerColor); }else{ return hasPiece(x-1,y,playerColor)+hasPiece(x,y-1,playerColor)+hasPiece(x-1,y-1,playerColor); } } } /* * Will check if the board has a valid connnection */ private int networkParser() { return 0; } }