void Awake() { object O = new object(); lock (O) { if (ArtificialInteligenceMove.Ret() != null) { if (ArtificialInteligenceMove.Ret().t == null) { ArtificialInteligenceMove.Ret().t = new RefrigtzChessPortable.RefrigtzChessPortableForm(); ArtificialInteligenceMove.Ret().t.Form1_Load(); RefrigtzChessPortable.AllDraw.UniqueLeafDetection = true; } } else { ArtificialInteligenceMove.tta = new ArtificialInteligenceMove(); if (ArtificialInteligenceMove.Ret().t == null) { ArtificialInteligenceMove.Ret().t = new RefrigtzChessPortable.RefrigtzChessPortableForm(); ArtificialInteligenceMove.Ret().t.Form1_Load(); RefrigtzChessPortable.AllDraw.UniqueLeafDetection = true; } } } }
public bool MoveAI() { object o = new object(); lock (o){ if (Order == 1) { ArtificialInteligenceMove.Ret().t.Play(k, p); ArtificialInteligenceMove.Ret().t.Play(m, s); Order = -1; return(true); } else if (Order == -1) { object oo = new object(); lock (oo){ RefrigtzChessPortable.AllDraw.MaxAStarGreedy = RefrigtzChessPortable.AllDraw.PlatformHelperProcessorCount; RefrigtzChessPortable.AllDraw.MaxAStarGreedy = RefrigtzChessPortable.AllDraw.PlatformHelperProcessorCount; RefrigtzChessPortable.AllDraw.MaxAStarGreedyHeuristicProgress = RefrigtzChessPortable.AllDraw.PlatformHelperProcessorCount; RefrigtzChessPortable.AllDraw.AStarGreedyiLevelMax = RefrigtzChessPortable.AllDraw.PlatformHelperProcessorCount; } object ooo = new object(); lock (oo){ int a = ArtificialInteligenceMove.Ret().t.Play(-1, -1); if (a == -2) { Debug.LogError("Table zero"); } x = ArtificialInteligenceMove.Ret().t.R.CromosomRowFirst; y = ArtificialInteligenceMove.Ret().t.R.CromosomColumnFirst; x1 = ArtificialInteligenceMove.Ret().t.R.CromosomRow; y1 = ArtificialInteligenceMove.Ret().t.R.CromosomColumn; } Order = 1; return(true); } } return(false); }
public void ThinkingIdle() { object O = new object(); lock (O){ Debug.Log("Idle method Begin"); bool ReadyZero = true; do { if (ArtificialInteligenceMove.Ret().t != null) { if (ArtificialInteligenceMove.Ret().t.LoadP || Idle) { if (RefrigtzChessPortable.AllDraw.CalIdle == 0 && ReadyZero) { Debug.Log("Ready to 0 base.AI"); ReadyZero = false; } if (RefrigtzChessPortable.AllDraw.CalIdle == 0 && (!ArtificialInteligenceMove.UpdateIsRunning) ) { bool Blit = RefrigtzChessPortable.AllDraw.Blitz; RefrigtzChessPortable.AllDraw.Blitz = false; Debug.Log("Idle Begin"); Idle = true; RefrigtzChessPortable.AllDraw.TimeInitiation = GameManager.a; RefrigtzChessPortable.AllDraw.MaxAStarGreedy = RefrigtzChessPortable.AllDraw.PlatformHelperProcessorCount * LevelMul; var arrayA = Task.Factory.StartNew(() => t.Draw.InitiateAStarGreedyt(RefrigtzChessPortable.AllDraw.MaxAStarGreedy, 1, 4, t.Draw.OrderP, CloneATable(t.brd.GetTable()), t.Draw.OrderP, false, false, 0)); //var arrayA =Task.Factory.StartNew(() => t.Play(-1,-1)); arrayA.Wait(); object i = new object(); lock (i) { bool LoadTree = false; (new RefrigtzChessPortable.TakeRoot()).Save(false, false, ArtificialInteligenceMove.Ret().t, ref LoadTree, false, false, false, false, false, false, false, true); } RefrigtzChessPortable.AllDraw.Blitz = Blit; // System.Threading.Thread.Sleep(50); //LevelMul++; Debug.Log("Idle Finished"); IdleProgress = false; ArtificialInteligenceMove.UpdateIsRunning = true; RefrigtzChessPortable.AllDraw.CalIdle = 1; } if (RefrigtzChessPortable.AllDraw.CalIdle == 2) { Debug.Log("Ready to 5 base"); RefrigtzChessPortable.AllDraw.CalIdle = 5; } // if(RefrigtzChessPortable.AllDraw.CalIdle==2) // { // Debug.Log("Ready to 5 base"); // // RefrigtzChessPortable.AllDraw.CalIdle=5; // } // Debug.Log("Ready to 0 base"); if (RefrigtzChessPortable.AllDraw.CalIdle == 5) { RefrigtzChessPortable.AllDraw.CalIdle = 1; // RefrigtzChessPortable.AllDraw.IdleInWork=false; Debug.Log("Ready to 1 base"); ReadyZero = true; } while (RefrigtzChessPortable.AllDraw.CalIdle == 1) { System.Threading.Thread.Sleep(1); } while (ArtificialInteligenceMove.UpdateIsRunning) { System.Threading.Thread.Sleep(1); } RefrigtzChessPortable.AllDraw.IdleInWork = true; RefrigtzChessPortable.AllDraw.CalIdle = 0; IdleProgress = true; // } } } while(RefrigtzChessPortable.AllDraw.CalIdle != 3); } }
void Update() { object pp = new object(); lock (pp) { bool aa = false; aa = ArtificialInteligenceMove.Ret() != null; aa = aa && ArtificialInteligenceMove.Ret().t != null; if (aa) { if (ArtificialInteligenceMove.Ret().t.LoadP) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Vector3 point = hit.point; Vector2Int gridPoint = Geometry.GridFromPoint(point); tileHighlight.SetActive(true); tileHighlight.transform.position = Geometry.PointFromGrid(gridPoint); if (Input.GetMouseButtonDown(0)) { // Reference Point 2: check for valid move location if (!Exist(moveLocations, gridPoint)) { return; } if (GameManager.instance.PieceAtGrid(gridPoint) == null) { GameManager.instance.Move(movingPiece, gridPoint); } else { GameManager.instance.CapturePieceAt(gridPoint); GameManager.instance.Move(movingPiece, gridPoint); } // Reference Point 3: capture enemy piece here later ExitState(); if (Order == 1) { object OO = new object(); lock (OO) { k = TileSelector.x; p = 7 - TileSelector.y; m = gridPoint.x; s = 7 - gridPoint.y; ff = System.Threading.Tasks.Task.Factory.StartNew(() => xc = MoveAI()); ff.Wait(); } } UnityThread.executeInUpdate(() => { var output = Task.Factory.StartNew(() => { object OOO = new object(); lock (OOO) { if (Order == -1) { OrB = 1; f = System.Threading.Tasks.Task.Factory.StartNew(() => xx = MoveAI()); f.Wait(); if (x != -1 && y != -1 && x1 != -1 && y1 != -1) { Debug.Log("Thinking Finished."); Vector2Int gridPointN = new Vector2Int(x, 7 - y); selectobject = GameManager.instance.PieceAtGrid(gridPointN); if (GameManager.instance.DoesPieceBelongToCurrentPlayer(selectobject)) { GameManager.instance.SelectPiece(selectobject); TileSelector.instance.ExitState(selectobject); } string A = "x:'" + x.ToString() + "';y:'" + y.ToString() + "';x1:'" + x1.ToString() + "';y1:'" + y1.ToString() + "'\r\n"; A += "================================================================================================\r\n"; System.IO.File.AppendAllText("A.txt" , A); // movingPiece=selectobject; // EnterState(selectobject); Vector2Int gridPointNN = new Vector2Int(x1, 7 - y1); MoveSelector.Instance.tileHighlight.SetActive(true); MoveSelector.Instance.tileHighlight.transform.position = Geometry.PointFromGrid(gridPointNN); if (MoveSelector.Instance.moveLocations.Count == 0) { Debug.Log("enter state not valid."); } if (!Exist(MoveSelector.Instance.moveLocations, gridPointNN)) { return; } // if (GameManager.instance.PieceAtGrid(gridPointNN) == null) { GameManager.instance.Move(MoveSelector.Instance.movingPiece, gridPointNN); } else { GameManager.instance.CapturePieceAt(gridPointNN); GameManager.instance.Move(MoveSelector.Instance.movingPiece, gridPointNN); } ExitState(); Debug.Log("Move Occured."); OrB = 1; xx = false; object OOOOO = new object(); lock (OOOOO) { tileHighlight.SetActive(false); x = ArtificialInteligenceMove.Ret().t.R.CromosomRowFirst = -1; y = ArtificialInteligenceMove.Ret().t.R.CromosomColumnFirst = -1; x1 = ArtificialInteligenceMove.Ret().t.R.CromosomRow = -1; y1 = ArtificialInteligenceMove.Ret().t.R.CromosomColumn = -1; RefrigtzChessPortable.AllDraw.CalIdle = 0; RefrigtzChessPortable.AllDraw.IdleInWork = true; } // } } else { Debug.LogError("Thinking Failed."); } } } }); output.Wait(); output.Dispose(); ArtificialInteligenceMove.UpdateIsRunning = false; }); } } else { tileHighlight.SetActive(false); } } } } }