コード例 #1
0
ファイル: Node.cs プロジェクト: longje/Eight-Square-Puzzle
 public Node(State state, Node parent, String action)
 {
     this.state = state;
     this.parent = parent;
     this.action = action;
     gValue = GoalValue.value(this);
     hValue = (state != null) ? Heuristics.heuristic(this) : 0;
     fValue = gValue + hValue;
 }
コード例 #2
0
ファイル: Node.cs プロジェクト: longje/Eight-Square-Puzzle
 public Node(State state)
 {
     this.state = state;
     this.parent = null;
     this.action = null;
     gValue = GoalValue.zeroGoalValue(this);
     hValue = (state != null) ? Heuristics.heuristic(this) : 0;
     fValue = gValue + hValue;
 }
コード例 #3
0
 public Boolean isGoalState(State values)
 {
     if (values != null)
       {
           String[] goalState = { "1", "2", "3", "4", "5", "6", "7", "8", "0" };
           int count = 0;
           foreach (List<Square> list in values.state)
           {
               foreach (Square block in list)
               {
                   if (!block.val.Equals(goalState[count]))
                   {
                       return false;
                   }
                   count++;
               }
           }
           return true;
       }
       return false;
 }
コード例 #4
0
ファイル: State.cs プロジェクト: bngreen/AStar
 public bool PerformAction(Action action, out State state)
 {
     state = null;
     int x, y;
     if (!GetZeroPosition(out x, out y))
         return false;
     var nx = x + action.MoveX;
     var ny = y + action.MoveY;
     if (!IsOnBounds(nx, ny))
         return false;
     state = new State();
     state.GridData = GridData;
     state[x, y] = state[nx, ny];
     state[nx, ny] = 0;
     return true;
 }
コード例 #5
0
ファイル: State.cs プロジェクト: longje/Eight-Square-Puzzle
        private State swapSquares(State st, Square activeSquare, Square zeroBlock)
        {
            String tempContent = activeSquare.val;
            int[] tempCoord = { activeSquare.X, activeSquare.Y };

            Square temp = st.state[activeSquare.X][activeSquare.Y];
            st.state[activeSquare.X][activeSquare.Y] = st.state[zeroBlock.X][zeroBlock.Y];
            st.state[zeroBlock.X][zeroBlock.Y] = temp;

            activeSquare.X = zeroBlock.X;
            activeSquare.Y = zeroBlock.Y;

            zeroBlock.X = tempCoord[0];
            zeroBlock.Y = tempCoord[1];

            return st;
        }
コード例 #6
0
 private void printChild(State st)
 {
     if (st != null)
       {
           foreach (List<Square> list in st.state)
           {
               foreach (Square block in list)
               {
                   Console.Write(block.val + " ");
               }
           }
           Console.WriteLine();
       }
 }