コード例 #1
0
        public Task <IEnumerable <SquareLocation> > GetLocationsAsync(CancellationToken token, Mark mark)
        {
            var locations = new SquareLocation[] { new SquareLocation()
                                                   {
                                                       Id = _locationId, Active = true
                                                   } }.ToList();

            return(Task.FromResult(locations.AsEnumerable()));
        }
コード例 #2
0
        //[Arguments(10, 10, 600, 600, CalculationType.Gpu)]
        public void AnalyzeImages(int SubsetDelta, int WindowDelta, int PointsinX, int PointsinY, CalculationType calculationType)
        {
            var            firstImage = ImageContainers.First().Value;
            var            square     = new SquareLocation(firstImage.BitmapWidth, firstImage.BitmapHeight);
            AnalyzeRequest request    = new AnalyzeRequest()
            {
                FindPoints       = ResolveFindPoints(calculationType),
                Arrays           = ImageContainers.ToDictionary(x => x.Key, x => x.Value.GrayScaleImage),
                SubsetDelta      = SubsetDelta,
                WindowDelta      = WindowDelta,
                PointsinX        = PointsinX,
                PointsinY        = PointsinY,
                StartingVertexes = square.CalculateStartingVertexes(PointsinX, PointsinY),
                BitmapHeight     = firstImage.BitmapHeight,
                BitmapWidth      = firstImage.BitmapWidth,
                Square           = square,
                Size             = ImageContainers.Count
            };
            var imageprocessor = new ImageProcessor(backgroundWorker, request);

            imageprocessor.Analyze(new DoWorkEventArgs(null));
        }
コード例 #3
0
    /**
     * Implements the exploring and backtracking part of the solution.
     */
    private bool Go(int numberOfMovesSoFar, HashSet <int> numberOfMovesForEachValidRoute, SquareLocation location)
    {
        // We start Upper-left
        foreach (var move in PossibleMoves)
        {
            // Move in a knightly way e.g. two down, one right
            var newLocation = location.Apply(move.FirstMove).Apply(move.SecondMove);

            if (newLocation.Col > NumCols - 1)      // TODO move this validation logic to SquareLocation class
            {
                continue;                           // try another move
            }
            else if (newLocation.Row > NumRows - 1) // TODO move this validation logic to SquareLocation class
            {
                continue;                           // try another move
            }
            else
            {
                // we're still on the board. Now see if the new location is 'blocked'
                bool isBlocked = A[newLocation.Row][newLocation.Col] == 1;
                if (isBlocked)
                {
                    continue; // try another move
                }
                else
                {
                    // OK, we're on the board and are on an unoccupied square. Are we on the target square?
                    if (newLocation.Col == NumCols - 1 && newLocation.Row == 0)
                    {
                        numberOfMovesForEachValidRoute.Add(numberOfMovesSoFar);
                        return(true);
                    }
                    else
                    {
                        // We're on an unoccupied space. Recurse all the new possible moves.
                        return(Go(numberOfMovesSoFar + 1, numberOfMovesForEachValidRoute, newLocation));
                    }
                }
            }
        }

        // backtrack
        return(false);
    }
コード例 #4
0
    /*
     *  PROBLEM:
     *  A is a matrix of :
     *
     *  N rows (first array)
     |
     |
     +----- M cols (second array)
     |
     |  given a zero-indexed matrix A consisting of N rows and M columns describing a chessboard, returns the minimum number of turns that the knight
     |  requires to move from the upper-left square to the lower-right square. The function should return -1 if it is impossible for the knight to
     |  move from the upper-left square to the lower-right square.
     |
     |  SOLUTION
     |  This is a backtracking problem with some book-keeping. We need to find all the valid routes whilst counting the number of moves for each one.
     |  Then we simply pick the min() value.
     */
    public int solution(int[][] A)
    {
        this.A  = A;
        NumRows = A.Length;
        NumCols = A[0].Length;

        // This is possibly overkill, in retrospect
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.UP, Num = NumSquaresMoved.TWO
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.LEFT, Num = NumSquaresMoved.ONE
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.UP, Num = NumSquaresMoved.TWO
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.RIGHT, Num = NumSquaresMoved.ONE
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.UP, Num = NumSquaresMoved.ONE
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.LEFT, Num = NumSquaresMoved.TWO
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.UP, Num = NumSquaresMoved.ONE
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.RIGHT, Num = NumSquaresMoved.TWO
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.DOWN, Num = NumSquaresMoved.ONE
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.LEFT, Num = NumSquaresMoved.TWO
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.DOWN, Num = NumSquaresMoved.ONE
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.RIGHT, Num = NumSquaresMoved.TWO
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.DOWN, Num = NumSquaresMoved.TWO
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.LEFT, Num = NumSquaresMoved.ONE
            }
        });
        PossibleMoves.Add(new Move {
            FirstMove = new DirectionalMove {
                Dir = Direction.DOWN, Num = NumSquaresMoved.TWO
            },
            SecondMove = new DirectionalMove {
                Dir = Direction.RIGHT, Num = NumSquaresMoved.ONE
            }
        });

        // Start at the Upper-left
        var location = new SquareLocation {
            Row = NumRows - 1, Col = 0
        };
        var numberOfMovesForEachValidRoute = new HashSet <int>();

        Go(0, numberOfMovesForEachValidRoute, location);

        if (numberOfMovesForEachValidRoute.Count > 0)
        {
            return(numberOfMovesForEachValidRoute.Min());
        }
        else
        {
            return(0);
        }
    }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SquareMouseEventArgs"/> class.
 /// </summary>
 /// <param name="location">
 /// The location of the square.
 /// </param>
 /// <param name="button">
 /// Which mouse button was pressed.
 /// </param>
 /// <param name="mouseLocation">
 /// The position of the mouse in pixels relative to the top left corner of the control.
 /// </param>
 public SquareMouseEventArgs(SquareLocation location, MouseButtons button, Point mouseLocation) : base(location)
 {
     Button        = button;
     MouseLocation = mouseLocation;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SquareEventArgs"/> class.
 /// </summary>
 /// <param name="location">
 /// The location of the square.
 /// </param>
 public SquareEventArgs(SquareLocation location)
 {
     Location = location;
 }