Similar Code Analysis Report

This document contains the results of performing a similar code analysis of projectscellsociety_team20 at 9/29/16 2:23 PM.

Table of contents

number of lines number of occurrences names of resources
26..23 2 FireSimulation, SegregationSimulation
12 2 SimulationScene
8..5 2 WartorSimulation
13..11 2 WartorSimulation
16 2 SquareGrid, HexagonGrid
5..4 2 TriangleCell, SquareCell
19..17 2 HexagonGrid, TriangleGrid
21 2 AntSimulation
4..3 3 WartorSimulation, Simulation
5..4 2 WartorSimulation
7 6 ControlPanel
3 2 XMLSimulationSceneCreator
6 2 FireSimulation, SegregationSimulation
21 2 FireSimulation, SegregationSimulation
19 2 FireSimulation, SegregationSimulation
9 2 HexagonGrid, TriangleGrid
7..4 4 WartorSimulation, AntSimulation, GameOfLifeSimulation
3 2 Grid
2 2 SquareGrid
6 2 FireSimulation, GameOfLifeSimulation
5 2 XMLSimulationSceneCreator
6 2 ControlPanel, SimulationScene
2 2 AntState, WartorState
2 2 Graph
2 2 XMLSave, XMLRead
1 2 WartorSimulation, FireSimulation
2 2 GameOfLifeSimulation
2 2 SquareGrid, HexagonGrid
2 3 TriangleCell, HexagonCell, SquareCell

List of matches

 

23..26 lines in FireSimulation, SegregationSimulation


SegregationSimulation
/cellsociety_team20/src/simulations/SegregationSimulation.java
FireSimulation
/cellsociety_team20/src/simulations/FireSimulation.java
   @Override 
   public void setSimulationSpecificConstants() { 
      HashMap<String, Double> numeric = format.getNumbers(); 
      HashMap<String, String> labels = format.getLabels(); 
      try { 
      EMPTY = new State("EMPTY", numeric.get("emptyID").intValue(), numeric.get("emptyRatio"),  
            getColor(labels.get("emptyColor"))); 
      POPULATION_A = new State("POPULATION A", numeric.get("popAID").intValue(), numeric.get("popARatio"),  
            getColor(labels.get("popAColor"))); 
      POPULATION_B = new State("POPULATION B", numeric.get("popBID").intValue(), numeric.get("popBRatio"),  
            getColor(labels.get("popBColor"))); 
      } 
      catch (Exception e) { 
         try { 
            throw new PropertyNotSpecifiedException("State IDs, ratios, or colors not given for all states."); 
         } 
         catch (Exception f) { 
            f.printStackTrace(); 
         } 
      } 
       
      satisfyThreshold = numeric.get("satisfyThreshold"); 
   } 
   @Override 
   public void setSimulationSpecificConstants() { 
      HashMap<String, Double> numeric = format.getNumbers(); 
      HashMap<String, String> labels = format.getLabels(); 
      try { 
         EMPTY = new State("EMPTY", numeric.get("emptyID").intValue(), numeric.get("emptyRatio"),  
               getColor(labels.get("emptyColor"))); 
         TREE = new State("TREE", numeric.get("treeID").intValue(), numeric.get("treeRatio"),  
               getColor(labels.get("treeColor"))); 
         BURNING = new State("BURNING", numeric.get("burningID").intValue(), numeric.get("burningRatio"),  
               getColor(labels.get("burningColor"))); 
      } 
      catch (Exception e) { 
         try { 
            throw new PropertyNotSpecifiedException("State IDs, ratios, or colors not given for all states."); 
         } 
         catch (Exception f){ 
            f.printStackTrace(); 
         } 
      } 
       
      if (numeric.get("probCatch") == null) 
         probCatch = 0.5; 
      else 
         probCatch = numeric.get("probCatch"); 
   } 
 

11..13 lines in WartorSimulation (x2)


WartorSimulation
/cellsociety_team20/src/simulations/WartorSimulation.java
WartorSimulation
/cellsociety_team20/src/simulations/WartorSimulation.java
            else if (Math.random() < 0.5) { 
               WartorState currentState = new WartorState("FISH", FISH, -122, Color.BLACK, -200 , REPRODUCECONSTANTFISH); 
               WartorState newState = new WartorState("FISH", FISH, -122, Color.BLACK, -200REPRODUCECONSTANTFISH); 
//               currentState.setId(FISH); 
//               newState.setId(FISH); 
//               currentState.setReproduce(REPRODUCECONSTANTFISH); 
//               newState.setReproduce(REPRODUCECONSTANTFISH); 
               grid.getCell(i, j).setCurrentState(currentState); 
               grid.getCell(i, j).setNewState(newState); 
            } 
            else 
            if (Math.random() < 0.4) { 
               WartorState currentState = new WartorState("SHARK", SHARK, -122, Color.BLACK, STARVECONSTANTREPRODUCECONSTANTSHARK); 
               WartorState newState = new WartorState("SHARK", SHARK, -122, Color.BLACK, STARVECONSTANTREPRODUCECONSTANTSHARK); 
//               currentState.setId(SHARK); 
//               newState.setId(SHARK); 
//               currentState.setReproduce(REPRODUCECONSTANTSHARK); 
//               newState.setReproduce(REPRODUCECONSTANTSHARK); 
//               currentState.setStarve(STARVECONSTANT); 
//               newState.setStarve(STARVECONSTANT); 
               grid.getCell(i, j).setCurrentState(currentState); 
               grid.getCell(i, j).setNewState(newState); 
            } 
            else if (Math.random() < 0.5) { 
 

16 lines in SquareGrid, HexagonGrid


HexagonGrid
/cellsociety_team20/src/ui/HexagonGrid.java
SquareGrid
/cellsociety_team20/src/ui/SquareGrid.java
   @Override 
   public void setVertices() { 
      for (int i = 0; i < grid.length; i++) { 
         for (int j = 0; j < grid[0].length; j++) { 
            ArrayList<Point> vertices = new ArrayList<Point>(); 
            double centerX = grid[i][j].getCenterPoint().getX(); 
            double centerY = grid[i][j].getCenterPoint().getY(); 
            for (int k = 0; k < 6; k++) { 
               double x = centerX - Math.sin((90 - 60*k)*Math.PI/180)*polygonSize
               double y = centerY + Math.cos((90 - 60*k)*Math.PI/180)*polygonSize
               vertices.add(new Point(x, y)); 
            } 
            grid[i][j].setVertices(vertices); 
         } 
      } 
   } 
   @Override 
   public void setVertices() { 
      for (int i = 0; i < grid.length; i++) { 
         for (int j = 0; j < grid[0].length; j++) { 
            ArrayList<Point> vertices = new ArrayList<Point>(); 
            double centerX = grid[i][j].getCenterPoint().getX(); 
            double centerY = grid[i][j].getCenterPoint().getY(); 
            for (int k = 0; k < 4; k++) { 
               double x = centerX - Math.signum(Math.sin((-45 + 90*k)*Math.PI/180))*polygonSize/2
               double y = centerY + Math.signum(Math.cos((-45 + 90*k)*Math.PI/180))*polygonSize/2
               vertices.add(new Point(x, y)); 
            } 
            grid[i][j].setVertices(vertices); 
         } 
      } 
   } 
 

17..19 lines in HexagonGrid, TriangleGrid


HexagonGrid
/cellsociety_team20/src/ui/HexagonGrid.java
TriangleGrid
/cellsociety_team20/src/ui/TriangleGrid.java
   @Override 
   public void setPolygonCenters() { 
      Point center = new Point(0.0, 0.0); 
      // Set centers for all the top row hexagons
      for (int j = 0; j < numCols; j++) { 
         grid[0][j].setCenterPoint(center); 
         if (j % 2 == 0) 
            center = new Point(center.getX() + polygonSize*3/2,  
                  center.getY() + polygonSize*Math.sqrt(3)/2); 
         else 
            center = new Point(center.getX() + polygonSize*3/2,  
                  center.getY() - polygonSize*Math.sqrt(3)/2); 
      } 
       
      // Set centers for all hexagons under the first row, using the first row as 
      // a basis. 
      for (int i = 1; i < numRows; i++) { 
         for (int j = 0; j < numCols; j++) { 
            Point p = grid[i-1][j].getCenterPoint(); 
   @Override 
   public void setPolygonCenters() { 
      Point center = new Point(0.0, 0.0); 
      // Set centers for all the top row triangles
      for (int j = 0; j < numCols; j++) { 
         grid[0][j].setCenterPoint(center); 
         if (j % 2 == 0) 
            center = new Point(center.getX() + polygonSize*0.5,  
                  center.getY() - polygonSize*Math.sqrt(3)/6); 
         else 
            center = new Point(center.getX() + polygonSize*0.5,  
                  center.getY() + polygonSize*Math.sqrt(3)/6); 
      } 
       
      for (int i = 1; i < numRows; i++) { 
         for (int j = 0; j < numCols; j++) { 
            Point p = grid[i-1][j].getCenterPoint(); 
 

21 lines in AntSimulation (x2)


AntSimulation
/cellsociety_team20/src/simulations/AntSimulation.java
AntSimulation
/cellsociety_team20/src/simulations/AntSimulation.java
   private void antFindFoodSource(Ant ant){ 
      AntState state=(AntState) ant.getCell().getCurrentState(); 
      ArrayList<Cell>neighbors=ant.getCell().getNeighbors(); 
      if(state.isNest()){ 
         ant.setOrientation(selectLocation(neighbors, "food")); 
      } 
      Cell c=selectLocation(forwardNeighbors(ant), "food"); 
      if(c==null){ 
         c=selectLocation(neighbors, "food"); 
      } 
      if(c!=null){ 
         dropHomePheromones(ant); 
         ant.setOrientation(c); 
         ant.setCell(c); 
         ant.setMoved(true); 
         AntState newState=(AntState)ant.getCell().getCurrentState(); 
         if(newState.isFoodSource()){ 
            ant.setHasFoodItem(true); 
         } 
      } 
   } 
   private void antReturnToNest(Ant ant){ 
      AntState state= (AntState)ant.getCell().getCurrentState(); 
      ArrayList<Cell>neighbors=ant.getCell().getNeighbors(); 
      if(state.isFoodSource()){ 
         ant.setOrientation(selectLocation(neighbors, "home")); 
      } 
      Cell c=selectLocation(forwardNeighbors(ant), "home"); 
      if(c==null){ 
         c=selectLocation(neighbors, "home"); 
      } 
      if(c!=null){ 
         dropFoodPheromones(ant); 
         ant.setOrientation(c); 
         ant.setCell(c); 
         ant.setMoved(true); 
         AntState newState=(AntState)ant.getCell().getCurrentState(); 
         if(newState.isNest()){ 
            ant.setHasFoodItem(false); 
         } 
      } 
   } 
 

21 lines in FireSimulation, SegregationSimulation


SegregationSimulation
/cellsociety_team20/src/simulations/SegregationSimulation.java
FireSimulation
/cellsociety_team20/src/simulations/FireSimulation.java
   public void setCellStatesInUI() { 
      for (int i = 0; i < grid.getNumRows(); i++) { 
         for (int j = 0; j < grid.getNumCols(); j++) { 
            Cell cell = grid.getCell(i, j); 
            State newState = cell.getNewState(); 
            if (newState.equals(EMPTY)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else if (newState.equals(POPULATION_A)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else if (newState.equals(POPULATION_B)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else { 
               System.out.print("error lmao"); 
            } 
            cell.setCurrentState(newState); 
         } 
      } 
   } 
   public void setCellStatesInUI() { 
      for (int i = 0; i < grid.getNumRows(); i++) { 
         for (int j = 0; j < grid.getNumCols(); j++) { 
            Cell cell = grid.getCell(i, j); 
            State newState = cell.getNewState(); 
            if (newState.equals(EMPTY)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else if (newState.equals(TREE)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else if (newState.equals(BURNING)) { 
               cell.getPolygon().setFill(newState.getColor()); 
            } 
            else { 
               System.out.print("error lmao"); 
            } 
            cell.setCurrentState(newState); 
         } 
      } 
   } 
 

19 lines in FireSimulation, SegregationSimulation


FireSimulation
/cellsociety_team20/src/simulations/FireSimulation.java
SegregationSimulation
/cellsociety_team20/src/simulations/SegregationSimulation.java
   @Override 
   public void initializeCellStates() { 
      for (int i = 0; i < grid.getNumRows(); i++) { 
         for (int j = 0; j < grid.getNumCols(); j++) { 
            if (Math.random() < EMPTY.getInitialRatio()) { 
               grid.getCell(i, j).setCurrentState(EMPTY); 
               grid.getCell(i, j).setNewState(EMPTY); 
            } 
            else if (Math.random() < EMPTY.getInitialRatio() + TREE.getInitialRatio()) { 
               grid.getCell(i, j).setCurrentState(TREE); 
               grid.getCell(i, j).setNewState(TREE); 
            } 
            else { 
               grid.getCell(i, j).setCurrentState(BURNING); 
               grid.getCell(i, j).setNewState(BURNING); 
            } 
         } 
      } 
   } 
   @Override 
   public void initializeCellStates() { 
      for (int i = 0; i < grid.getNumRows(); i++) { 
         for (int j = 0; j < grid.getNumCols(); j++) { 
            if (Math.random() < EMPTY.getInitialRatio()) { 
               grid.getCell(i, j).setCurrentState(EMPTY); 
               grid.getCell(i, j).setNewState(EMPTY); 
            } 
            else if (Math.random() < EMPTY.getInitialRatio() + POPULATION_A.getInitialRatio()) { 
               grid.getCell(i, j).setCurrentState(POPULATION_A); 
               grid.getCell(i, j).setNewState(POPULATION_A); 
            } 
            else { 
               grid.getCell(i, j).setCurrentState(POPULATION_B); 
               grid.getCell(i, j).setNewState(POPULATION_B); 
            } 
         } 
      } 
   } 
9/29/16 2:23 PM Powered by CodePro Server