public override void CalculateBestMove(Game.Piece myTurn, out int x, out int y, int sizeX, int sizeY) { x = 4; y = 4; var max = float.MinValue; for (var i = 0; i < sizeX; i++) { for (var j = 0; j < sizeY; j++) { //仮想の盤面を作成 var board = new Game.Piece[sizeX, sizeY]; Array.Copy(_game.Board, board, _game.Board.Length); var set = _game.SetPiece(i, j, ref board); if (!set) { continue; } var point = Net(board, (int)myTurn); //Red=-1なので掛けることで符号反転 if (point <= max) { continue; } x = i; y = j; max = point; } } }
public override void CalculateBestMove(Game.Piece myTurn, out int x, out int y, int sizeX, int sizeY) { if (!_isGetting) { StartCoroutine(GetPlayerMove()); } x = _x; y = _y; }
public void Render(int x, int y, Game.Piece turn) { if (x == -1 || y == -1) { return; } var go = turn == Game.Piece.Blue ? _blue : _red; var obj = Instantiate(go, new Vector3(x, 0.25f, y) * _space, go.transform.rotation); _gameObjects.Add(obj); }
/// <summary> /// Play中はtrueを返す /// </summary> /// <param name="red"></param> /// <param name="blue"></param> /// <returns></returns> public IEnumerator <bool> Play(Brain red, Brain blue) { var players = new Dictionary <Game.Piece, Brain> { { Game.Piece.Red, red }, { Game.Piece.Blue, blue }, { Game.Piece.Null, null } }; //print("start"); red.SetMyTurn(Game.Piece.Red); blue.SetMyTurn(Game.Piece.Blue); var x = 0; var y = 0; _game.ResetBoad(); do { // print(_game.Turn); var player = players[_game.Turn]; player.DeterminePosition = false; player.CalculateBestMove(_game.Turn, out x, out y, SizeX, SizeY); if (_doRendering) { _renderer.Render(x, y, _game.Turn); } yield return(true); } while (!_game.Move(x, y)); Winner = _game.Winner; if (_writeConsole) { var s = "Winner:" + Winner + "(player:" + players[Winner] + "):\n"; for (var i = 0; i < _game.Board.GetLength(0); i++) { for (var j = 0; j < _game.Board.GetLength(1); j++) { s += _game.Board[i, j] + " "; } s += '\n'; } print(s); } if (_doRendering) { _renderer.Clean(); } yield return(false); }
private void SquareClicked(object sender, MouseEventArgs e) { RemoveAllLitSquares(); if (sender.GetType().Name == "Viewbox") { Viewbox v = (Viewbox)sender; string name = v.Name; SidePanelTextBox.Text += "\n" + name + " clicked."; SidePanelTextBox.ScrollToEnd(); // get coords from name string[] vals = name.Split('_'); if (vals.Count() == 3) { string x_str = vals[1]; string y_str = vals[2]; int x = x_str[0] - '0'; int y = y_str[0] - '0'; SidePanelTextBox.Text += String.Format("X: {0} Y: {1}", x, y); string PngName = ((Image)v.Child).Source.ToString(); PngName = 6 > PngName.Length ? PngName : PngName.Substring(PngName.Length - 6); // get piece from dict string PieceName = GetPieceFromPngName(PngName); SidePanelTextBox.Text += String.Format(" {0} {1}", PngName, PieceName); LightUpBorderOnGrid(x, y); // light the current piece // get piece on board char xchr = (y + 1).ToString()[0]; char ychr = (x + 1).ToString()[0]; Game.Piece p = Game.GetPieceOnSquare(Board, xchr, ychr); SelectedCoordinate = new coordinate(x, y); SelectedPiece = p; // get possible moves List <Point> pts = Game.ValidMoves(Board, p); // convert them and light them up foreach (Point pt in pts) { LightUpBorderOnGrid((int)pt.Y - 1, (int)pt.X - 1); } } // get image name from grid? } }
public override void CalculateBestMove(Game.Piece myTurn, out int x, out int y, int sizeX, int sizeY) { x = 3; y = 3; var max = float.MinValue; var unbest = UnityEngine.Random.Range(0, 5) == 0; for (var i = 0; i < sizeX; i++) { for (var j = 0; j < sizeY; j++) { var bestx = x; var besty = y; //仮想の盤面を作成 var board = new Game.Piece[sizeX, sizeY]; Array.Copy(_game.Board, board, _game.Board.Length); var set = _game.SetPiece(i, j, ref board); if (!set) { continue; } x = i; y = j; if (unbest && UnityEngine.Random.Range(0, 5) == 0) { break; } var point = _game.CountSequence(MyTurn, i, j, board); if (point <= max) { x = bestx; y = besty; continue; } max = point; } } }
public void SetMyTurn(Game.Piece turn) { MyTurn = turn; }
public abstract void CalculateBestMove(Game.Piece myTurn, out int x, out int y, int sizeX, int sizeY);