Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class GameTactic {
- char[][] matrix;
- int size;
- public GameTactic(char[][] matrix, int size) {
- this.matrix = matrix;
- this.size = size;
- }
- public int GenerateCost(Node n){
- if(this.matrix[n.getRow()][n.getCol()]=='R'){
- return 1;
- }
- if(this.matrix[n.getRow()][n.getCol()]=='D'){
- return 3;
- }
- if(this.matrix[n.getRow()][n.getCol()]=='H'){
- return 10;
- }
- return -1;
- }
- public List<Node> GetPossibleNeigh(Node n){
- int row=n.getRow();
- int col=n.getCol();
- List<Node> possibleNeigh=new ArrayList<>();
- //R
- if(col<size && matrix[row][col+1]!='W') {
- Node R = new Node(row,col+1);
- R.setPath("R");
- possibleNeigh.add(R);
- }
- //RD
- if(col<size && row<size && matrix[row][col+1]!='W' && matrix[row+1][col]!='W' && matrix[row+1][col+1]!='W') {
- Node RD = new Node(row+1,col+1);
- RD.setPath("RD");
- possibleNeigh.add(RD);
- }
- //D
- if(row<size && matrix[row+1][col]!='W') {
- Node D = new Node(row+1,col);
- D.setPath("D");
- possibleNeigh.add(D);
- }
- //DL
- if(col>0 && row<size && matrix[row+1][col-1]!='W' && matrix[row+1][col]!='W' && matrix[row][col-1]!='W') {
- Node DL = new Node(row+1,col-1);
- DL.setPath("DL");
- possibleNeigh.add(DL);
- }
- //L
- if(col>0 && matrix[row][col-1]!='W') {
- Node L = new Node(row,col-1);
- L.setPath("L");
- possibleNeigh.add(L);
- }
- //LU
- if(col>0 && row>0 && matrix[row-1][col-1]!='W' && matrix[row-1][col]!='W' && matrix[row][col-1]!='W') {
- Node LU = new Node(row-1,col-1);
- LU.setPath("LU");
- possibleNeigh.add(LU);
- }
- //U
- if(row>0 && matrix[row-1][col]!='W') {
- Node U = new Node(row-1,col);
- U.setPath("U");
- possibleNeigh.add(U);
- }
- //RU
- if(col<size && row>0 && matrix[row-1][col+1]!='W' && matrix[row-1][col]!='W' && matrix[row][col+1]!='W') {
- Node RU = new Node(row-1,col+1);
- RU.setPath("RU");
- possibleNeigh.add(RU);
- }
- return possibleNeigh;
- }
- public boolean IsGoal(Node n){
- if(n.getRow()==size-1 && n.getCol()==size-1){
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement