public void PlayerPlace(sbyte color, int i) { var status = IController.Status.INVALIDACTION; while (status != IController.Status.OK) { if (_millPositions[i] == -1) { var placing = new Placing(color, i); status = _controller.Play(placing); Debug.WriteLine(status); if (status == IController.Status.CLOSEDMILL) { for (int k = 0; k < _millPositions.Length; k++) { if (_millPositions[k] == State.OppositeColor(color)) { Debug.WriteLine($"Take {k} from Computer"); _controller.Play(new Taking(placing, k)); break; } } } } i++; } _millPositions[i - 1] = color; }
void MakeGhost() { placed = Instantiate(Contents[Equiped_num - 1].Model, new Vector3(0, 0, 0), Quaternion.identity); placed.transform.SetParent(place_space.transform); placed.transform.position = new Vector3(0, 0, 0); placed.transform.localRotation = Quaternion.identity; placed.transform.localPosition = Vector3.zero; placed.transform.localScale = Vector3.one; placed.name = Contents[Equiped_num - 1].Name; Collider[] colls = placed.gameObject.GetComponents <Collider>(); foreach (Collider coll in colls) { coll.isTrigger = true; } placed.gameObject.GetComponent <Placing>().enabled = true; placed.layer = 0; placed.SetActive(true); ghostActive = true; p = placed.gameObject.GetComponent <Placing>(); }
public void UpdateHoverBlock(Block block) { selected = block; if (mode is Placing) { Placing placing = (Placing)mode; placing.ChangeHoverBlock(block); } }
/** * Creates a new game tree: the first action is white, on the next level plays black. * White is a maximizer, black is a minimizer. * @param pa null if computer plays white, first action if human plays white */ public void Create(int height, Placing pa) { if (pa == null) { // First move made by computer var placing = new Placing(IController.WHITE, 10); m_currentNode = new MaxNode(placing); _firstTurn = true; } else { m_currentNode = new MaxNode(pa); } m_root = m_currentNode; m_currentState = new State(); m_currentNode.Data().Update(m_currentState); m_root.Create(0, height, IController.BLACK, m_root, m_currentState); m_height = height; }
/** * Place stone s on board * @param a Action */ public void Update(Placing a) { if (a == null) { throw new Exception("action is null"); } var pos = a.EndPosition; var color = a.Color(); if (!IsValidPlace(pos, color)) { throw new Exception("invalid action"); } m_board[pos] = color; m_unplacedStones[color]--; m_stonesOnBoard[color]++; }
/// <summary> /// Creates the childrens of the Node with alpha–beta pruning /// </summary> /// <param name="curHeight">current subtree height</param> /// <param name="height">height Subtree height</param> /// <param name="color">Color of next actions</param> /// <param name="root">Subtree root</param> /// <param name="rootState">Game state at root</param> /// <param name="alpha"></param> /// <param name="beta"></param> /// <returns>The </returns> public int Create(int curHeight, int height, sbyte color, GameNode root, State rootState, int alpha, int beta) { if (curHeight == height || rootState.Finished()) { return(rootState.Score()); } var v = (color == IController.WHITE) ? int.MinValue : int.MaxValue; if (rootState.PlacingPhase(color)) { foreach (byte position in State.TRANSPOSED) { if (!rootState.IsValidPlace(position, color)) { continue; } var nextAction = new Placing(color, position); var newState = rootState.Clone(); nextAction.Update(newState); var childNode = Create(nextAction, root); if (newState.InMill(position, color)) { if (newState.TakingIsPossible(State.OppositeColor(color))) { foreach (byte takingPosition in State.TRANSPOSED) { if (newState.IsValidTake(takingPosition, State.OppositeColor(color))) { var takeState = rootState.Clone(); var takingAction = new Taking(nextAction, takingPosition); takingAction.Update(takeState); var takingNode = Create(takingAction, root); //Minimizer if (color == IController.WHITE) { v = Math.Max(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode, takeState, alpha, beta)); alpha = Math.Max(alpha, v); } else //Maximizer { v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode, takeState, alpha, beta)); beta = Math.Min(beta, v); } UpdateScore(takingNode, v); root.m_children.Enqueue(takingNode); if (beta <= alpha) { break; } } } } } else { //Minimizer if (color == IController.WHITE) { v = Math.Max(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode, newState, alpha, beta)); alpha = Math.Max(alpha, v); } else //Maximizer { v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode, newState, alpha, beta)); beta = Math.Min(beta, v); } UpdateScore(childNode, v); root.m_children.Enqueue(childNode); if (beta <= alpha) { break; } } } } else if (rootState.MovingPhase(color) || rootState.JumpingPhase(color)) { for (byte i = 0; i < rootState.Board.Length; i++) { var moves = (rootState.JumpingPhase(color)) ? State.TRANSPOSED : State.MOVES[i]; foreach (byte to in moves) { if (!rootState.IsValidMove(i, to, color)) { continue; } var nextAction = new Moving(color, i, to); var childNode = Create(nextAction, root); var newState = rootState.Clone(); childNode.Data().Update(newState); if (newState.InMill(to, color)) { if (newState.TakingIsPossible(State.OppositeColor(color))) { foreach (byte takingPosition in State.TRANSPOSED) { if (!newState.IsValidTake(takingPosition, State.OppositeColor(color))) { continue; } var takingNode = Create(new Taking(nextAction, takingPosition), root); var takeState = rootState.Clone(); takingNode.Data().Update(takeState); //Minimizer if (color == IController.WHITE) { v = Math.Max(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode, takeState, alpha, beta)); alpha = Math.Max(alpha, v); } else //Maximizer { v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode, takeState, alpha, beta)); beta = Math.Min(beta, v); } UpdateScore(takingNode, v); root.m_children.Enqueue(takingNode); if (beta <= alpha) { break; } } } } else { //Minimizer if (color == IController.WHITE) { v = Math.Max(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode, newState, alpha, beta)); alpha = Math.Max(alpha, v); } else //Maximizer { v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode, newState, alpha, beta)); beta = Math.Min(beta, v); } UpdateScore(childNode, v); root.m_children.Enqueue(childNode); if (beta <= alpha) { break; } } } } } return(v); }