void Start() { HidePanels(); _defaultGates = new Dictionary <string, QCS.Gate>(); _customGates = new Dictionary <string, QCS.Gate>(); GameMode.gates.ForEach(AddDefaultGate); GameMode.customGates.ForEach(AddCustomGateToMenu); circuits = GameMode.circuits; _currentCircuitIndex = 0; gridBoard = new GridBoard(gridGame, currentCircuit); gridBoard.PositionInitialCamera(); if (Input.touchSupported) { CurrentState = new Smartphone_States.DefaultState(this); } else { CurrentState = new PC_States.DefaultState(this); } inputController = new InputController(this); SetLevelName(); }
/// <summary> /// Execution function for Day 3 /// </summary> public void Execute3() { UserActionAsync(() => { WriteToConsole("Start execution of Day3"); var parser = GetInputParser("Day3Input.txt"); var startingPoint = new CoordinatePoint(0, 0); var wires = parser.GetInputData().Select(line => new Wire(startingPoint, line.Split(','))).ToList(); var wire1 = wires[0]; var wire2 = wires[1]; var intersections = wire1.GetIntersectionsWith(wire2); var board = new GridBoard(); var closestPoint = board.GetClosestPointTo(intersections, startingPoint); WriteToConsole($"The closest intersection point is located at {closestPoint.point} with a distance to the starting point of {closestPoint.distance}"); AddEmptyLine(); WriteToConsole($"Now we want to find the closest intersection based on the steps both wires combined have to take to reach it"); var firstIntersection = wire1.GetFirstIntersectionWith(wire2); WriteToConsole($"The first intersection point is located at {firstIntersection.point} with a total number of {firstIntersection.steps} steps"); AddEmptyLine(); }); }
public void Paint(Graphics gfx, GridBoard board, Rectangle bounds) { var stepX = bounds.Width / board.Width; var stepY = bounds.Height / board.Height; var ellipse = new Rectangle(((SpleefPlayerInfo)Info).CurrentLocation.X * stepX, ((SpleefPlayerInfo)Info).CurrentLocation.Y * stepY, stepX, stepY); gfx.FillEllipse(new SolidBrush(((SpleefPlayerInfo)Info).PlayerColor), ellipse); gfx.DrawEllipse(Pens.Black, ellipse); var words = Info.Name.Split(' '); var stringToDraw = string.Join("\r\n", words); var longestWordLength = words.OrderByDescending(x => x.Length).First().Length; if (longestWordLength > 7) { longestWordLength--; } if (longestWordLength > 9) { longestWordLength--; } var drawFont = new Font("Arial", stepX / longestWordLength, FontStyle.Bold); var drawFormat = new StringFormat(); drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; gfx.DrawString(stringToDraw, drawFont, Brushes.Black, ellipse, drawFormat); }
void Start() { capture = new VideoCapture(0); capture.ImageGrabbed += HandleGrab; dico = new Dictionary(Dictionary.PredefinedDictionaryName.Dict4X4_50); grid = new GridBoard(4, 4, 80, 30, dico); arucoParam = DetectorParameters.GetDefault(); }
//gets tile position in world space Vector3 GetWorldTilePos(Tile tile) { Vector3 worldPos = GridBoard.CalcWorldPosFromCoords(tile.X, tile.Y); //y coordinate is disregarded worldPos.y = 0; return(worldPos); }
private void Awake() { boardCorners = new PointF[4]; markerPositions = new PointF[4]; markerWrapPositions = new PointF[4]; markerDict = new Dictionary(Dictionary.PredefinedDictionaryName.Dict4X4_50); gridBoard = new GridBoard(4, 4, 80, 30, markerDict); arucoParameters = DetectorParameters.GetDefault(); }
public static bool PlayGrid(GridType type, GridRepository repository) { //logger.Trace("Downloading grid {0}", type); GridBoard grid = repository.GetGridByType(type); int awards = grid.GetCellTypeCount(CellState.Award); int unknown = grid.GetCellTypeCount(CellState.Hidden); int empty = grid.GetCellTypeCount(CellState.Empty); int items = grid.GetCellTypeCount(CellState.Item); int awardsLeft = 22 - awards; double odds = awardsLeft / (double)unknown; double itemOdds = (8 - items) / (double)unknown; if (lastUnknown != unknown) { logger.Info("{0} shows {1} awards, {2} empty, {3} unknown, {4} items, {5:0.00000%} item odds, {6:0.00000%} odds", type, awards, empty, unknown, items, itemOdds, odds); lastUnknown = unknown; } //if (odds >= .315) //{ // Cell cell = grid.GetFirstHiddenCell(); // logger.Trace("Buying ticket {0}", cell.TicketId); // grid = repository.PurchaseGridTicket(grid, cell.TicketId); // Cell newCell = grid.GetCellByTicketId(cell.TicketId); // if (newCell.State == CellState.Award) // { // wins++; // logger.Info("Ticket {0} won!", cell.TicketId); // } else if (newCell.State == CellState.Empty) // { // losses++; // logger.Info("Ticket {0} was empty.", cell.TicketId); // } else // { // logger.Warn("Cell state for ticket {0} did not change on purchase", cell.TicketId); // } // rolls++; // double winOdds = wins / (double)(wins + losses); // logger.Info("{1} wins, {2} losses, {3} rolls, winning percentage {4:0.00%}", type, wins, losses, rolls, winOdds); // return true; //} else //{ // logger.Info("Skipping because of bad odds"); //} return(false); }
public void Init(int x, int y) { X = x; Y = y; var t = gameObject.transform; t.SetParent(null); t.localPosition = GridBoard.CalcWorldPosFromCoords(x, y); t.localRotation = Quaternion.identity; t.localScale = Vector3.one; t.SetParent(GridBoard.Instance.transform); gameObject.layer = GridBoard.Instance.gameObject.layer; }
public void DistanceAndStepTest(List <string> wire1, List <string> wire2, int distance, int steps) { var startingPoint = new CoordinatePoint(0, 0); var w1 = new Wire(startingPoint, wire1); var w2 = new Wire(startingPoint, wire2); var intersections = w1.GetIntersectionsWith(w2); var board = new GridBoard(); var closestPoint = board.GetClosestPointTo(intersections, startingPoint); var firstIntersection = w1.GetFirstIntersectionWith(w2); Assert.IsTrue(closestPoint.distance == distance); Assert.IsTrue(firstIntersection.steps == steps); }
public void Paint(Graphics gfx, GridBoard board, Rectangle bounds) { var stepX = bounds.Width / board.Width; var stepY = bounds.Height / board.Height; var ellipse = new Rectangle(((ColorCrazePlayerInfo)Info).CurrentLocation.X * stepX, ((ColorCrazePlayerInfo)Info).CurrentLocation.Y * stepY, stepX, stepY); gfx.FillEllipse(new SolidBrush(((ColorCrazePlayerInfo)Info).PlayerColor), ellipse); gfx.DrawEllipse(Pens.Black, ellipse); var drawFont = new Font("Arial", stepX / 10); var drawFormat = new StringFormat(); drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; gfx.DrawString(Info.Name, drawFont, Brushes.Black, ellipse, drawFormat); }
public TurnSimulator(GridBoard board) { this.board = board; }
void Awake() { Instance = this; SetSizes(); CreateGrid(); }
/// <summary> /// Raises the webcam texture to mat helper initialized event. /// </summary> public void OnWebCamTextureToMatHelperInitialized() { Debug.Log("OnWebCamTextureToMatHelperInitialized"); Mat webCamTextureMat = webCamTextureToMatHelper.GetMat(); texture = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGB24, false); gameObject.GetComponent <Renderer> ().material.mainTexture = texture; gameObject.transform.localScale = new Vector3(webCamTextureMat.cols(), webCamTextureMat.rows(), 1); Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation); if (fpsMonitor != null) { fpsMonitor.Add("width", webCamTextureMat.width().ToString()); fpsMonitor.Add("height", webCamTextureMat.height().ToString()); fpsMonitor.Add("orientation", Screen.orientation.ToString()); } float width = webCamTextureMat.width(); float height = webCamTextureMat.height(); float imageSizeScale = 1.0f; float widthScale = (float)Screen.width / width; float heightScale = (float)Screen.height / height; if (widthScale < heightScale) { Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2; imageSizeScale = (float)Screen.height / (float)Screen.width; } else { Camera.main.orthographicSize = height / 2; } // set camera parameters. double fx; double fy; double cx; double cy; string loadDirectoryPath = Path.Combine(Application.persistentDataPath, "ArUcoCameraCalibrationExample"); string calibratonDirectoryName = "camera_parameters" + width + "x" + height; string loadCalibratonFileDirectoryPath = Path.Combine(loadDirectoryPath, calibratonDirectoryName); string loadPath = Path.Combine(loadCalibratonFileDirectoryPath, calibratonDirectoryName + ".xml"); if (useStoredCameraParameters && File.Exists(loadPath)) { CameraParameters param; XmlSerializer serializer = new XmlSerializer(typeof(CameraParameters)); using (var stream = new FileStream(loadPath, FileMode.Open)) { param = (CameraParameters)serializer.Deserialize(stream); } camMatrix = param.GetCameraMatrix(); distCoeffs = new MatOfDouble(param.GetDistortionCoefficients()); fx = param.camera_matrix [0]; fy = param.camera_matrix [4]; cx = param.camera_matrix [2]; cy = param.camera_matrix [5]; Debug.Log("Loaded CameraParameters from a stored XML file."); Debug.Log("loadPath: " + loadPath); } else { int max_d = (int)Mathf.Max(width, height); fx = max_d; fy = max_d; cx = width / 2.0f; cy = height / 2.0f; camMatrix = new Mat(3, 3, CvType.CV_64FC1); camMatrix.put(0, 0, fx); camMatrix.put(0, 1, 0); camMatrix.put(0, 2, cx); camMatrix.put(1, 0, 0); camMatrix.put(1, 1, fy); camMatrix.put(1, 2, cy); camMatrix.put(2, 0, 0); camMatrix.put(2, 1, 0); camMatrix.put(2, 2, 1.0f); distCoeffs = new MatOfDouble(0, 0, 0, 0); Debug.Log("Created a dummy CameraParameters."); } Debug.Log("camMatrix " + camMatrix.dump()); Debug.Log("distCoeffs " + distCoeffs.dump()); // calibration camera matrix values. Size imageSize = new Size(width * imageSizeScale, height * imageSizeScale); double apertureWidth = 0; double apertureHeight = 0; double[] fovx = new double[1]; double[] fovy = new double[1]; double[] focalLength = new double[1]; Point principalPoint = new Point(0, 0); double[] aspectratio = new double[1]; Calib3d.calibrationMatrixValues(camMatrix, imageSize, apertureWidth, apertureHeight, fovx, fovy, focalLength, principalPoint, aspectratio); Debug.Log("imageSize " + imageSize.ToString()); Debug.Log("apertureWidth " + apertureWidth); Debug.Log("apertureHeight " + apertureHeight); Debug.Log("fovx " + fovx [0]); Debug.Log("fovy " + fovy [0]); Debug.Log("focalLength " + focalLength [0]); Debug.Log("principalPoint " + principalPoint.ToString()); Debug.Log("aspectratio " + aspectratio [0]); // To convert the difference of the FOV value of the OpenCV and Unity. double fovXScale = (2.0 * Mathf.Atan((float)(imageSize.width / (2.0 * fx)))) / (Mathf.Atan2((float)cx, (float)fx) + Mathf.Atan2((float)(imageSize.width - cx), (float)fx)); double fovYScale = (2.0 * Mathf.Atan((float)(imageSize.height / (2.0 * fy)))) / (Mathf.Atan2((float)cy, (float)fy) + Mathf.Atan2((float)(imageSize.height - cy), (float)fy)); Debug.Log("fovXScale " + fovXScale); Debug.Log("fovYScale " + fovYScale); // Adjust Unity Camera FOV https://github.com/opencv/opencv/commit/8ed1945ccd52501f5ab22bdec6aa1f91f1e2cfd4 if (widthScale < heightScale) { arCamera.fieldOfView = (float)(fovx [0] * fovXScale); } else { arCamera.fieldOfView = (float)(fovy [0] * fovYScale); } // Display objects near the camera. arCamera.nearClipPlane = 0.01f; rgbMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC3); ids = new Mat(); corners = new List <Mat> (); rejectedCorners = new List <Mat> (); rvecs = new Mat(); tvecs = new Mat(); rotMat = new Mat(3, 3, CvType.CV_64FC1); detectorParams = DetectorParameters.create(); dictionary = Aruco.getPredefinedDictionary((int)dictionaryId); rvec = new Mat(); tvec = new Mat(); recoveredIdxs = new Mat(); gridBoard = GridBoard.create(gridBoradMarkersX, gridBoradMarkersY, gridBoradMarkerLength, gridBoradMarkerSeparation, dictionary, gridBoradMarkerFirstMarker); charucoCorners = new Mat(); charucoIds = new Mat(); charucoBoard = CharucoBoard.create(chArUcoBoradSquaresX, chArUcoBoradSquaresY, chArUcoBoradSquareLength, chArUcoBoradMarkerLength, dictionary); diamondCorners = new List <Mat> (); diamondIds = new Mat(1, 1, CvType.CV_32SC4); diamondIds.put(0, 0, new int[] { diamondId1, diamondId2, diamondId3, diamondId4 }); // if WebCamera is frontFaceing, flip Mat. if (webCamTextureToMatHelper.GetWebCamDevice().isFrontFacing) { webCamTextureToMatHelper.flipHorizontal = true; } }
private void CreateMaeker() { if (markerImg.cols() != markerSize) { markerImg.Dispose(); markerImg = new Mat(markerSize, markerSize, CvType.CV_8UC3); texture = new Texture2D(markerImg.cols(), markerImg.rows(), TextureFormat.RGB24, false); } else { markerImg.setTo(Scalar.all(255)); } gameObject.transform.localScale = new Vector3(markerImg.cols(), markerImg.rows(), 1); float width = markerImg.width() / 0.7f; float height = markerImg.height() / 0.7f; float widthScale = (float)Screen.width / width; float heightScale = (float)Screen.height / height; if (widthScale < heightScale) { Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2; gameObject.transform.localPosition = new Vector3(0, -height * 0.1f, 0); } else { Camera.main.orthographicSize = height / 2; gameObject.transform.localPosition = new Vector3(width * 0.1f, 0, 0); } // create dictinary. Dictionary dictionary = Aruco.getPredefinedDictionary((int)dictionaryId); // draw marker. switch (markerType) { default: case MarkerType.CanonicalMarker: Aruco.drawMarker(dictionary, (int)markerId, markerSize, markerImg, borderBits); Debug.Log("draw CanonicalMarker: " + "dictionaryId " + (int)dictionaryId + " markerId " + (int)markerId + " sidePixels " + markerSize + " borderBits " + borderBits); break; case MarkerType.GridBoard: GridBoard gridBoard = GridBoard.create(gridBoradMarkersX, gridBoradMarkersY, gridBoradMarkerLength, gridBoradMarkerSeparation, dictionary, gridBoradMarkerFirstMarker); gridBoard.draw(new Size(markerSize, markerSize), markerImg, gridBoradMarginSize, borderBits); gridBoard.Dispose(); Debug.Log("draw GridBoard: " + "markersX " + gridBoradMarkersX + " markersY " + gridBoradMarkersY + " markerLength " + gridBoradMarkerLength + " markerSeparation " + gridBoradMarkerSeparation + "dictionaryId " + (int)dictionaryId + " outSize " + markerSize + " marginSize " + gridBoradMarginSize + " borderBits " + borderBits); break; case MarkerType.ChArUcoBoard: CharucoBoard charucoBoard = CharucoBoard.create(chArUcoBoradMarkersX, chArUcoBoradMarkersY, chArUcoBoradSquareLength, chArUcoBoradMarkerLength, dictionary); charucoBoard.draw(new Size(markerSize, markerSize), markerImg, chArUcoBoradMarginSize, borderBits); charucoBoard.Dispose(); Debug.Log("draw ChArUcoBoard: " + "markersX " + chArUcoBoradMarkersX + " markersY " + chArUcoBoradMarkersY + " markerLength " + chArUcoBoradSquareLength + " markerSeparation " + chArUcoBoradMarkerLength + "dictionaryId " + (int)dictionaryId + " outSize " + markerSize + " marginSize " + chArUcoBoradMarginSize + " borderBits " + borderBits); break; } Utils.matToTexture2D(markerImg, texture); }
protected override void UpdateCurrentBoard(GridBoard board) { currentBoard = new Connect4Board(board); }
public StraitCapture(GridBoard board) { this.board = board; }
public Connect4Board(GridBoard gb) : base(boardWidth, boardHeight, gb.grid) { }
/// <summary> /// Returns a board in which the given move has been applied by the given player. /// </summary> public Connect4Board SimulateMove(Connect4Board board, int player, int move) { GridBoard gridBoard = base.SimulateMove(board, player, move); return(new Connect4Board(gridBoard)); }
void Awake() { current = this; }