id
stringlengths
36
36
text
stringlengths
1
1.25M
a81d3e1a-aa7c-4e1e-804e-b612dc93e282
public ItemEBShovel(ToolMaterial material) { super(material); }
69affb8a-b333-42ee-a91e-6035ef03c834
@Override public boolean onBlockDestroyed(ItemStack tool, World world, Block block, int x, int y, int z, EntityLivingBase user) { if(user instanceof EntityPlayer && canMine(block) && !world.isRemote) { EntityPlayer player = (EntityPlayer)user; int lvlE = tool.stackTagCompound.getInteger("lvl"); Block dropBlock = block; MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D); int limit = 0; int count = 0; int xStart = lvlE; int xStop = lvlE; int yStart = 1; int yStop = lvlE == 1 ? 1 : 3; int zStart = lvlE; int zStop = lvlE; //0 = Bottom, 1 = Top, 2 = , 3 = , 4 = East, 5 = West switch (mop.sideHit) { case 0: System.out.println("Hit Bottom"); yStart = 0; yStop = 2*lvlE; break; case 1: System.out.println("Hit Top"); yStart = 2*lvlE; yStop = 0; break; case 2: System.out.println("Hit 2"); zStart = 0; zStop = 2*lvlE; break; case 3: System.out.println("Hit 3"); zStart = 2*lvlE; zStop = 0; break; case 4: System.out.println("Hit 4"); xStart = 0; xStop = 2*lvlE; break; case 5: System.out.println("Hit 5"); xStart = 2*lvlE; xStop = 0; break; } Slot slot; ArrayList<Integer> slots = new ArrayList(); ArrayList<Integer> numInSlot = new ArrayList(); int drops = 0; for(int i = 9; i < 45; i++) { slot = player.inventoryContainer.getSlot(i); if (slot.getStack() == null) { slots.add(i); numInSlot.add(64); drops += 64; } else if(slot.getStack().getItem() == Item.getItemFromBlock(dropBlock) && slot.getStack().stackSize < slot.getSlotStackLimit()) { slots.add(i); numInSlot.add(slot.getSlotStackLimit() - slot.getStack().stackSize); drops += slot.getSlotStackLimit() - slot.getStack().stackSize; } } int max = lvlE == 1 ? 27 : 125; drops = drops > max ? max : drops; limit = drops; for (int xPos = x - xStart; xPos <= x + xStop; xPos++) { for (int yPos = y - yStart; yPos <= y + yStop; yPos++) { for (int zPos = z - zStart; zPos <= z + zStop; zPos++) { if(world.getBlock(xPos, yPos, zPos) == block) { if(limit < 1) { break; } world.setBlockToAir(xPos, yPos, zPos); count++; limit--; } } } } if(tool.stackTagCompound.getBoolean("drops") == true) { drops = count; Iterator slotIt = slots.iterator(); Iterator dropsIt = numInSlot.iterator(); int putInSlot; int currentSlot; int putStackSize; int currStackSize; while(drops > 0) { putInSlot = (Integer)dropsIt.next(); currentSlot = (Integer)slotIt.next(); try { currStackSize = player.inventoryContainer.getSlot(currentSlot).getStack().stackSize; } catch(NullPointerException e) { currStackSize = 0; } if(putInSlot > drops) putInSlot = drops; putStackSize = currStackSize + putInSlot; player.inventoryContainer.putStackInSlot(currentSlot, new ItemStack(dropBlock, putStackSize)); drops -= putInSlot; } } } return true; }
6a2cb29c-099f-4280-bf92-4fd4bbfbae13
private boolean canMine(Block block) { return block == Blocks.dirt ? true : block == Blocks.sand ? true : block == Blocks.gravel ? true : false; }
f3228e67-5056-455e-9ae2-0cdcf0ecad2d
@Override public void onCreated(ItemStack item, World world, EntityPlayer player) { item.stackTagCompound = new NBTTagCompound(); item.stackTagCompound.setInteger("lvl", 1); item.stackTagCompound.setBoolean("drops", true); }
b821cbba-a298-44c8-99ae-350ca1375cf2
@Override public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { if(player.isSneaking()) { ItemStack result = item; Boolean drops = result.stackTagCompound.getBoolean("drops"); result.stackTagCompound.setBoolean("drops", drops == true ? false : true); return result; } return item; }
d26779fc-695e-4b71-9142-b2625a693103
public ItemBBSword(ToolMaterial material) { super(material); this.setCreativeTab(Ref.tab); }
e911517b-66b5-4808-8185-2133e2a130f0
public ItemBBShovel(ToolMaterial material) { super(material); this.setCreativeTab(Ref.tab); }
a637ea74-b5ba-44c6-abe1-da97090340cf
public ItemBBAxe(ToolMaterial material) { super(material); this.setCreativeTab(Ref.tab); }
5c64b73f-b238-4c43-8489-5020093f6e6d
public ItemBBEnchant(int ench) { super(); this.setCreativeTab(Ref.tab); this.setMaxStackSize(1); }
eb48b77b-df65-4ba1-bb00-fe886a876bcd
public ItemThickAxe(ToolMaterial material) { super(EnumHelper.addToolMaterial("thick" + material.name(), material.getHarvestLevel(), material.getMaxUses()*4, material.getEfficiencyOnProperMaterial(), material.getDamageVsEntity(), material.getEnchantability())); this.setCreativeTab(Ref.tab); }
02e8b1cc-1ab2-4a30-bb06-a1bb2ad7eb5c
public ItemBBPick(ToolMaterial material) { super(material); this.setCreativeTab(Ref.tab); }
cf3fb864-97b1-494f-a6cc-cbd55e7cf7ca
public ItemThickPickaxe(ToolMaterial material) { super(EnumHelper.addToolMaterial("thick" + material.name(), material.getHarvestLevel(), (int)(material.getMaxUses()*3.75), (float)(material.getEfficiencyOnProperMaterial()*1.15), material.getDamageVsEntity(), material.getEnchantability())); this.setCreativeTab(Ref.tab); }
5a5f28a3-cbaf-4887-a0c8-a290fcaa34be
public ItemSmashedOre() { super(); this.setUnlocalizedName("smashedOre"); }
e873da9e-a81e-42f1-be27-760a6e13af64
@Override public void onUpdate(ItemStack item, World world, Entity entity, int int1, boolean bool) { }
3572ecc2-6e6b-4361-820b-ece45e2ba793
public static void main(String[] args) { PApplet.main(new String[]{ "controller.Main"}); }
821d0fbc-5ad9-4afd-8d1e-4677bcd90439
public void setup() { size(GuiConfig.SCREEN_WIDTH, GuiConfig.SCREEN_HEIGHT); this.screenWidth = GuiConfig.SCREEN_WIDTH; this.screenHeight = GuiConfig.SCREEN_HEIGHT; background(100, 100, 100); env = new Environment(this); }
d9a18927-c9b8-40ad-be95-4e59edd39854
public void draw() { env.draw(); }
bae09bb9-929d-4558-b460-2a28f51768ab
public void mouseClicked() { // testliste mit vordefinierten zuegen!! LinkedList<Symbol> results = new LinkedList<Symbol>(); Minimax mmPlayerMax = new Minimax(Player.MAX, BOARD_SIZE); Minimax mmPlayerMin = new Minimax(Player.MIN, BOARD_SIZE); State prevState = new State(); Coordinate2D co = env.get_board().get_clicked_coordinates(); System.out.println("Section: " + co.section); int field = co.section; int x = (field) % BOARD_SIZE; int y = (field - x) / BOARD_SIZE; prevState.field[y][x] = 1; State currState = prevState.deepCopy(); results.add(new Cross(field)); System.out.println(prevState.toString()); for (int i=0; i<BOARD_SIZE*BOARD_SIZE-1; i++) { if(mmPlayerMax.terminalTest(currState) || mmPlayerMin.terminalTest(currState)) break; if (i%2 == 0) currState = mmPlayerMin.getMinimaxDecision(prevState); else currState = mmPlayerMax.getMinimaxDecision(prevState); results.add(this.stateToSymbol(prevState, currState)); prevState = currState.deepCopy(); System.out.println(prevState.toString()); } // results.add( new Cross(10) ); // results.add( new Circle(6) ); // results.add( new Cross(11) ); // results.add( new Circle(9) ); // results.add( new Cross(15) ); // results.add( new Circle(5) ); // results.add( new Cross(7) ); // results.add( new Circle(3) ); // results.add( new Cross(12) ); // results.add( new Circle(13) ); // results.add( new Cross(1) ); // results.add( new Circle(14) ); // results.add( new Cross(8) ); // results.add( new Circle(0) ); // results.add( new Cross(2) ); // // results.add( new Circle(4) ); env.get_board().set_results( results ); }
d5db065c-0ad1-47a0-9206-03f1670e7e8a
private Symbol stateToSymbol(State prevState, State currState) { for(int i=0; i<BOARD_SIZE; i++) { for(int j=0; j<BOARD_SIZE; j++) { if(prevState.field[i][j] != currState.field[i][j]) { if(currState.field[i][j] == 1) return new Cross(i*BOARD_SIZE+j); else return new Circle(i*BOARD_SIZE+j); } } } return null; }
c6591ced-8b66-4221-b0b1-76826c92a92d
public void draw();
b0aa1ec0-f944-4227-b827-74a9507e3e9f
public Coordinate2D get_clicked_coordinates();
937433eb-63f3-4217-8ac5-aa17cd9cdc9b
void set_results( LinkedList<Symbol> results);
ac81fa08-e822-45bb-9ea8-1708187fbff6
public void draw( PApplet gui, float x, float y, float width, float height, int transparency);
38736ea7-80cb-4252-a741-6a676548b81c
public int get_section();
65a444e1-a3b0-4c6d-aac5-08572a33eb96
public Board2D( PApplet gui) { this.gui = gui; this.mouse_coordinates = new Coordinate2D( ); board_x = (GuiConfig.SCREEN_WIDTH/2) - (GuiConfig.BOARD_WIDTH/2); board_y = (GuiConfig.SCREEN_HEIGHT/2) - (GuiConfig.BOARD_HEIGHT/2); cell_width = GuiConfig.BOARD_WIDTH / GuiConfig.BOARD_COLUMNS; cell_height = GuiConfig.BOARD_HEIGHT / GuiConfig.BOARD_COLUMNS; }
08be7079-bf09-4a0c-8061-704d36ddfac2
public void set_results( LinkedList<Symbol> results ) { this.results = results; this.results_animated = new LinkedList<Symbol>(); }
c7db1974-f9d1-4df7-9c68-c52f3f149174
@Override public void draw() { gui.smooth(); gui.strokeWeight(2); gui.stroke(100, 100, 100); this.draw_plane( board_x, board_y ); this.draw_columns( board_x, board_y ); this.draw_rows( board_x, board_y ); this.draw_symbols(); }
006a20a9-c9d9-4943-92df-7013735e3b5b
private void draw_symbols() { this.fill_results_animated(); Coordinate2D co = new Coordinate2D(); int margin = GuiConfig.MARGIN; Iterator<Symbol> it = this.results_animated.iterator(); int size_counter = 1; while( it.hasNext() ) { Symbol sym = it.next(); Coordinate2D temp = co.calculate_coordinates2D_from_section(this.board_x, this.board_y, this.cell_width, this.cell_height, sym.get_section() ); // aktuell animierter zug if( size_counter == results_animated.size() ) { sym.draw(this.gui, temp.section_x + margin, temp.section_y + margin, this.cell_width - (margin * 2), this.cell_height - (margin * 2),transparency); this.calculate_transparency_bounds(); } else { // alte züge sym.draw(this.gui, temp.section_x + margin, temp.section_y + margin, this.cell_width - (margin * 2), this.cell_height - (margin * 2),255); } ++size_counter; } }
1eccf574-a2b3-4f02-bb93-c7e83f36ded7
private void calculate_transparency_bounds() { int speed = GuiConfig.TRANSPARENCY_SPEED; if( speed > 30 ) speed = 30; if( speed < 5 ) speed = 5; if( this.transparency >= 255 ) this.transparency = 255; this.transparency += speed; }
f0247e79-831e-4326-bb93-ad9bc4cfebeb
private void fill_results_animated() { ++step_counter; if( step_counter % this.get_animation_speed() == 0 ) { if( results.size() > 0 ) { results_animated.add( results.removeFirst() ); transparency = 0; } } if( step_counter >= 255 ) step_counter = 0; }
7d29b93a-1a10-4d17-a8ce-1cf91f13e45b
private int get_animation_speed() { int speed = 100 - GuiConfig.SPEED; if( speed < 10 ) speed = 10; if( speed > 100 ) speed = 100; return speed; }
4ae26a9b-d8a5-4d25-ae2a-29ded0fff086
@Override public Coordinate2D get_clicked_coordinates( ) { this.mouse_coordinates.mouse_x = gui.mouseX; this.mouse_coordinates.mouse_y = gui.mouseY; Coordinate2D co = mouse_coordinates.calculate_coordinates2D(board_x, board_y, cell_width, cell_height); return co; }
36bba7ff-d2a5-439b-b253-33a740773225
private void draw_rows( float board_x, float board_y ) { for( int i = 1; i <= GuiConfig.BOARD_COLUMNS; ++i ) { float row_x1 = board_x; float row_x2 = board_x + GuiConfig.BOARD_WIDTH; float row_y = board_y + i * (GuiConfig.BOARD_HEIGHT / GuiConfig.BOARD_COLUMNS); gui.fill(0,255,255); gui.line( row_x1, row_y, row_x2, row_y ); } }
45cc06ab-9ca1-47c8-aff6-42def3eab8c7
private void draw_plane( float board_x, float board_y ) { gui.fill(255,255,255); gui.rect( board_x , board_y,GuiConfig.BOARD_WIDTH, GuiConfig.BOARD_HEIGHT ); }
d02e45ff-e6e2-4fd9-b5dc-fd63b651ff7a
private void draw_columns( float board_x, float board_y ) { for( int i = 1; i <= GuiConfig.BOARD_COLUMNS; ++i ) { float column_x = board_x + i * (GuiConfig.BOARD_WIDTH / GuiConfig.BOARD_COLUMNS); float column_y1 = board_y; float column_y2 = board_y + GuiConfig.BOARD_HEIGHT; gui.fill(0,255,255); gui.line( column_x, column_y1, column_x, column_y2 ); } }
54341c6f-1f66-49ba-82ae-cbdaf919e16c
public Environment( PApplet applet ) { this.gui = applet; this.setup(); this.board = new Board2D(gui); }
36a8c589-b733-491c-b797-0cd016ab7102
public void setup() { }
24227d24-4635-4eaa-ad1a-3fb6e26a34a8
public void set_board( Board bord ) { this.board = bord; }
b2c96e03-b8ac-4b9f-983f-a4c41d2d8fbb
public Board get_board() { return this.board; }
0c5e3936-7667-47df-b598-9553af6d5578
public void draw() { this.board.draw(); }
58f60a00-b3d0-4fba-bdda-ceb7c26a7ccb
public Coordinate2D( ) { }
b7b7d7f0-4f71-4c35-ba9f-85e6e5d42497
public Coordinate2D(int section, float mouse_x, float mouse_y, float section_x, float section_y) { this.section = section; this.mouse_x = mouse_x; this.mouse_y = mouse_y; this.section_x = section_x; this.section_y = section_y; }
944d0b5c-6515-4d42-a194-1b62d4399624
public Coordinate2D calculate_coordinates2D(float board_x, float board_y, float cell_width, float cell_height ) { int section_counter = 0; this.section = section_counter; for( int i = 1; i <= GuiConfig.BOARD_COLUMNS; ++i ) { float start_y = (board_y + i * cell_height) - cell_height; float end_y = (board_y + i * cell_height); for( int j = 1; j <= GuiConfig.BOARD_COLUMNS; ++j ) { float start_x = (board_x + j * cell_width) - cell_width; float end_x = (board_x + j * cell_width); if( is_within_coordinate_range( start_x, start_y, end_x, end_y ) ) { this.section = section_counter; System.out.println("Feld: "+section_counter); return new Coordinate2D( section_counter, this.mouse_x, this.mouse_y, start_x, start_y ); } ++section_counter; } } // wenn außerhalb der grenzen geklickt, dann Koordinaten für erstes feld zurückgeben float start_x = (board_x + cell_width) - cell_width; float start_y = (board_y + cell_height) - cell_height; return new Coordinate2D( 0, this.mouse_x, this.mouse_y, start_x, start_y ); }
ce20fd71-d757-409d-a7e6-534281b4b676
public Coordinate2D calculate_coordinates2D_from_section(float board_x, float board_y, float cell_width, float cell_height, int section ) { int section_counter = 0; this.section = section_counter; for( int i = 1; i <= GuiConfig.BOARD_COLUMNS; ++i ) { float start_y = (board_y + i * cell_height) - cell_height; float end_y = (board_y + i * cell_height); for( int j = 1; j <= GuiConfig.BOARD_COLUMNS; ++j ) { float start_x = (board_x + j * cell_width) - cell_width; float end_x = (board_x + j * cell_width); if( section_counter == section ) { return new Coordinate2D( section_counter, 0, 0, start_x, start_y ); } ++section_counter; } } // wenn außerhalb der grenzen geklickt, dann Koordinaten für erstes feld zurückgeben float start_x = (board_x + cell_width) - cell_width; float start_y = (board_y + cell_height) - cell_height; return new Coordinate2D( 0, this.mouse_x, this.mouse_y, start_x, start_y ); }
b04c13ff-ef80-4021-b3c2-73c748a10bda
private boolean is_within_coordinate_range( float start_x, float start_y, float end_x, float end_y ) { if( this.mouse_x >= start_x && this.mouse_x < end_x ) { if( this.mouse_y >= start_y && this.mouse_y < end_y ) { return true; } } return false; }
45fe0fc0-6a21-4f81-b863-1bd3ddb0f03e
public Circle( int section ) { this.section = section; }
d8317daa-9b2a-4cba-a1f9-70a4c39e0184
@Override public void draw(PApplet gui, float x, float y, float width, float height, int transparency) { gui.ellipseMode(PApplet.CORNER); int offset = 5; gui.strokeWeight(GuiConfig.STROKE-5); gui.stroke( 200,200,200,transparency ); gui.ellipse(x+offset,y+offset,width,height); gui.fill(255,255,255); gui.smooth(); gui.strokeWeight(GuiConfig.STROKE); gui.stroke( 255,0,0,transparency ); gui.ellipse(x,y,width,height); }
d58b07b5-e4d4-4a4f-bb96-7973171ff091
@Override public int get_section() { return this.section; }
aae994f8-12c8-494a-b723-523e9346f687
public Cross( int section ) { this.section = section; }
b9e039b2-b109-433d-a722-e1d676bbd7ce
@Override public void draw(PApplet gui, float x, float y, float width, float height, int transparency) { gui.fill(255,255,255); gui.smooth(); gui.strokeWeight(GuiConfig.STROKE); gui.stroke( 0,0,255,transparency ); gui.line( x, y, x+width, y+height ); gui.line( x+width, y, x, y+height ); /* gui.pushMatrix(); gui.translate( x, y ); gui.rotate(PApplet.radians(45)); gui.translate( -x, -y ); gui.rect( x + height/5, y + height/10, width, height/10 ); gui.popMatrix(); */ }
c7de2abf-379e-4824-8ad2-0b9759728605
@Override public int get_section() { return this.section; }
76737460-6203-4461-a2e5-fb334933a855
RectButton(PApplet gui, int ix, int iy, int isize) { super(gui, ix, iy, isize); this.gui = gui; x = ix; y = iy; size = isize; }
9faa6336-5b2b-4aa4-b168-6393aabe7a6a
boolean over() { if( overRect(x, y, size, size) ) { over = true; return true; } else { over = false; return false; } }
5f96f4e4-db0f-49b9-a9a0-7d14da5b5acb
void draw() { gui.stroke(255); gui.fill(255,255,255); gui.rect(x, y, size, size); }
a0a445a6-fcec-4bce-a2c8-8db1c61e0991
public Action deepCopy() { Action copy = new Action(); copy.row = this.row; copy.col = this.col; copy.player = this.player; return copy; }
46394c1b-d78b-432f-acce-8e61980615d0
public State() { field = new int[Minimax.boardSize][Minimax.boardSize]; for(int i=0; i<Minimax.boardSize; i++) for(int j=0; j<Minimax.boardSize; j++) field[i][j] = 0; }
c61a5cfb-8a5b-442a-a1e5-ef4be3ec4fe2
public State deepCopy() { State copy = new State(); for(int i=0; i<Minimax.boardSize; i++) for(int j=0; j<Minimax.boardSize; j++) copy.field[i][j] = this.field[i][j]; return copy; }
a3f98f23-dfe6-4bc1-8f3f-885c5af84cfc
public String toString() { String s = ""; for (int i=0; i<Minimax.boardSize; i++) { s += "|"; for (int j=0; j<Minimax.boardSize; j++) { if (field[i][j] == 1) s += "X"; else if (field[i][j] == -1) s += "O"; else s += " "; } s += "|\n"; } return s; }
8c4e0bba-9417-438b-94a5-e7335e32c0d4
public Minimax(Player p, int boardSize) { this.player = p; Minimax.boardSize = boardSize; }
b72e8150-ec61-469a-9c51-8051acefebba
public State getMinimaxDecision(State initialState) { System.out.println("player: " + player); long t1 = System.currentTimeMillis(); Action bestAction = null; double bestUtility = Double.NEGATIVE_INFINITY; List<Action> actionList = getActions(initialState); for (Action action : actionList) { double utility = minValue(getResult(initialState, action)); if (utility > bestUtility) { bestUtility = utility; bestAction = action.deepCopy(); } } State resultState = getResult(initialState, bestAction); long t2 = System.currentTimeMillis(); System.out.println("TIME: " + (t2-t1) + "ms"); return resultState; }
e7fd037c-48c1-468f-b3d4-84de56ce0483
private double minValue(State state) { double utility = Double.POSITIVE_INFINITY; if (terminalTest(state)) { // System.out.println("terminal: "); // System.out.println(state.toString()); // System.out.println(""); return utility(state); } List<Action> actionList = getActions(state); for (Action action: actionList) { double tmp = maxValue(getResult(state, action)); utility = Math.min(utility,tmp); } return utility; }
2bd10f7d-8d6a-46d9-b042-77ce1113dbcb
private double maxValue(State state) { double utility = Double.NEGATIVE_INFINITY; if (terminalTest(state)) { // System.out.println("terminal: "); // System.out.println(state.toString()); // System.out.println(""); return utility(state); } List<Action> actionList = getActions(state); for (Action action: actionList) { double tmp = minValue(getResult(state,action)); utility = Math.max(utility, tmp); } return utility; }
59e16a3d-ec4a-4e87-b8c8-ee2175ff1d06
private State getResult(State currentState, Action action) { State resultState = currentState.deepCopy(); if (action.player == Player.MAX) resultState.field[action.col][action.row] = 1; else resultState.field[action.col][action.row] = -1; // System.out.println("CURRENT RESULT: "); // System.out.println(resultState.toString()); // System.out.println(""); return resultState; }
db9ea0b1-3a64-4663-96c4-e57a8ca6c3c5
private List<Action> getActions(State state) { List<Action> actions = new ArrayList<Action>(); int moves = 0; for (int i=0; i<boardSize; i++) for (int j =0; j<boardSize; j++) if(state.field[i][j] != 0) moves++; Player player = Player.MAX; if(moves % 2 == 1) player = Player.MIN; for (int i=0; i<boardSize; i++) { for (int j =0; j<boardSize; j++) { if (state.field[i][j] == 0) { Action action = new Action(); action.col = i; action.row = j; action.player = player; actions.add(action); } } } return actions; }
e374f281-09e8-4873-aaae-b1de37cc6797
private int utility(State state) { int val = 0; for (int i=0; i<boardSize; i++) val += state.field[i][i]; if (val == boardSize && player == Player.MAX || val == -boardSize && player == Player.MIN) return 1; if ( val == boardSize && player == Player.MIN || val == -boardSize && player == Player.MAX) return -1; val=0; for (int i=0; i<boardSize; i++) val += state.field[i][boardSize-i-1]; if (val == boardSize && player == Player.MAX || val == -boardSize && player == Player.MIN) return 1; if ( val == boardSize && player == Player.MIN || val == -boardSize && player == Player.MAX) return -1; for (int i=0; i<boardSize; i++) { val = 0; for (int j=0; j<boardSize; j++) val += state.field[i][j]; if (val == boardSize && player == Player.MAX || val == -boardSize && player == Player.MIN) return 1; if ( val == boardSize && player == Player.MIN || val == -boardSize && player == Player.MAX) return -1; } for (int j=0; j<boardSize; j++) { val = 0; for (int i=0; i<boardSize; i++) val += state.field[i][j]; if (val == boardSize && player == Player.MAX || val == -boardSize && player == Player.MIN) return 1; if ( val == boardSize && player == Player.MIN || val == -boardSize && player == Player.MAX) return -1; } return 0; }
fb907455-306b-4c3d-9276-7cb4e2ade4bd
public boolean terminalTest(State state) { int playedFields = 0; for (int i=0; i<boardSize; i++) { int totalRow = 0; for (int j=0; j<boardSize; j++) { if (state.field[i][j] != 0) playedFields++; totalRow += state.field[i][j]; } if (Math.abs(totalRow) == boardSize) return true; } if (playedFields == boardSize*boardSize) return true; for (int j=0; j<boardSize; j++) { int total = 0; for (int i=0; i<boardSize; i++) total += state.field[i][j]; if (Math.abs(total) == boardSize) return true; } int total = 0; for (int i=0; i<boardSize; i++) total += state.field[i][i]; if (Math.abs(total) == boardSize) return true; total=0; for (int i=0; i<boardSize; i++) total += state.field[i][boardSize-i-1]; if (Math.abs(total) == boardSize) return true; return false; }
35ed15d6-a3dd-4a7c-b4ee-64b4611f817d
List<T> queryForList(RowMapper<T> rowMapper) throws SQLException;
0efe4856-be7f-4db7-ae35-d11dbb0c9a35
T queryForObject(RowMapper<T> rowMapper) throws SQLException;
88d9ce69-1b98-4a9b-bbe5-3484856b16af
String queryForString() throws SQLException;
931c3018-9970-4413-bff5-4df9e5453360
Integer queryForInteger() throws SQLException;
69441116-3915-4245-8c8d-f26e818a2394
Long queryForLong() throws SQLException;
c833a2d3-ced2-4eea-9b7e-631a461950fa
Date queryForDate() throws SQLException;
f381767c-02ac-4a55-9d0e-374a7de12ef3
Date queryForTimestamp() throws SQLException;
464c1d0e-340c-4785-9c52-6977d9deb9a4
Boolean queryForBoolean() throws SQLException;
4a7c4f7e-5a62-4974-8a1a-75ef79434988
Query<T> setString(String name, String value) throws SQLException;
1ae74ce5-aa01-42af-b6be-2ebeceb5fe47
Query<T> setInteger(String name, Integer value) throws SQLException;
a5d74895-b5e4-4650-b429-132128a68420
Query<T> setLong(String name, Long value);
9a54ead5-f71a-44c6-9ef7-6e4c3ad1bd0b
Query<T> setDate(String name, Date value);
52f6503b-36aa-4338-ae76-dc8f4cb18b52
Query<T> setBoolean(String name, Boolean value);
f5e9ec41-5128-47ba-9a9b-3d10edbec582
Query<T> setTimestamp(String name, Date value);
e368dee9-fda6-4f6f-affb-a743aa6df7dd
void execute() throws SQLException;
571820d2-b760-44c2-8da3-cc6c24a73071
void commit() throws SQLException;
13c0d8aa-7501-4a09-8c87-2ce9b404e3f0
void rollback() throws SQLException;
f7163bd6-cf94-46e6-8526-782640a37e6e
Query query(String statement) throws SQLException;
bbd72636-d38a-4895-8e4d-06f8929cbdc9
Update update(String statement) throws SQLException;
baf646e9-0e89-4d8a-ad14-fcb4100f7881
public DatabaseException() { }
ba0a9794-a926-4f66-b551-ad65d082312a
public DatabaseException(String message) { super(message); }
d3dd7fb4-f2bb-4ae9-94ec-4d2f1f5e7586
public DatabaseException(String message, Throwable cause) { super(message, cause); }
80abd021-beb6-4d8e-ad66-27a21710544c
public DatabaseException(Throwable cause) { super(cause); }
002ef386-8777-4438-a027-82affc688095
public DatabaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); }
a0a30f55-ae93-47bd-ab08-939a3a954778
T mapRow(ResultSet rs) throws SQLException;
35fd8577-e0c3-45cf-a376-b92ba6eafa31
public Database(DataSource dataSource) { this.dataSource = dataSource; }
f10dadaa-e515-4860-aacb-18fce44debc6
public Database(String driver, String url, String username, String password) { dataSource = new BasicDataSource(); ((BasicDataSource) dataSource).setDriverClassName(driver); ((BasicDataSource) dataSource).setUrl(url); ((BasicDataSource) dataSource).setUsername(username); ((BasicDataSource) dataSource).setPassword(password); }
ef13492c-a2d7-4dbb-8ae3-86f8ae40fa37
public void close() throws SQLException { if (dataSource instanceof BasicDataSource) { ((BasicDataSource) dataSource).close(); } }
0deaf505-f44e-4990-9b8c-3f51462a5457
public Query query(String statement) throws SQLException { return new QueryImpl(dataSource.getConnection(), statement, true); }
182737c5-96bf-41e8-98dd-3045fc7c4ad2
public Update update(String statement) throws SQLException { return new UpdateImpl(dataSource.getConnection(), statement, true); }
7447c420-a154-4d37-9cd3-087a86e647af
public Transaction startTransaction() throws SQLException { return new TransactionImpl(dataSource.getConnection()); }
3cfec606-28a0-4962-8d3e-1f8bf3c6bec4
public NamedParameterStatement(Connection connection, String query) throws SQLException { indexMap = new HashMap(); String parsedQuery = parse(query, indexMap); statement = connection.prepareStatement(parsedQuery); }
40b3a525-6197-4869-8db8-dcc1ac08ab4d
static final String parse(String query, Map paramMap) { // I was originally using regular expressions, but they didn't work well //for ignoring // parameter-like strings inside quotes. int length = query.length(); StringBuilder parsedQuery = new StringBuilder(length); boolean inSingleQuote = false; boolean inDoubleQuote = false; int index = 1; for (int i = 0; i < length; i++) { char c = query.charAt(i); if (inSingleQuote) { if (c == '\'') { inSingleQuote = false; } } else if (inDoubleQuote) { if (c == '"') { inDoubleQuote = false; } } else { if (c == '\'') { inSingleQuote = true; } else if (c == '"') { inDoubleQuote = true; } else if (c == ':' && i + 1 < length && Character.isJavaIdentifierStart(query.charAt(i + 1))) { int j = i + 2; while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) { j++; } String name = query.substring(i + 1, j); c = '?'; // replace the parameter with a question mark i += name.length(); // skip past the end if the parameter List indexList = (List) paramMap.get(name); if (indexList == null) { indexList = new LinkedList(); paramMap.put(name, indexList); } indexList.add(Integer.valueOf(index)); index++; } } parsedQuery.append(c); } // replace the lists of Integer objects with arrays of ints for (Iterator itr = paramMap.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); List list = (List) entry.getValue(); int[] indexes = new int[list.size()]; int i = 0; for (Iterator itr2 = list.iterator(); itr2.hasNext(); ) { Integer x = (Integer) itr2.next(); indexes[i++] = x.intValue(); } entry.setValue(indexes); } return parsedQuery.toString(); }
4ee1e6d4-24df-49ac-9deb-e98d7a4d7a02
public Set getParameterNames() { return indexMap.keySet(); }