public virtual bool CanAvoidThreatInAMov(out IAMovement.Movement mov) { mov = new IAMovement.Movement(); Tile[] tiles = GetPosibleMovementsNoPlayerColumn(); int aux_x = _x, aux_y = _y; bool can = false; foreach (Tile t in tiles) { bool valid = false; _x = t.x; _y = t.y; for (int i = 0; i < 3; i++) { valid |= CanGoToFrom(t.x, t.y, player.x + i, player.y); } if (!valid) { mov.isEmpty = false; mov.piece = this; mov.tile = t; can = true; break; } } _x = aux_x; _y = aux_y; return(can); }
public virtual void MoveToRandom(out IAMovement.Movement mov) { Tile[] posibleMovs = GetPosibleMovementsNoPlayerColumn(); Tile dest = posibleMovs[Random.Range(0, posibleMovs.Length)]; mov = new IAMovement.Movement(); mov.isEmpty = false; mov.tile = dest; mov.piece = this; }
//Return true if player can be kill in next move public bool CanKillPlayerInMove(ref IAMovement.Movement mov) { mov = new IAMovement.Movement(); foreach (Tile t in GetPosibleMovements()) { LayerMask lm = LayerMask.GetMask("Player"); if (Physics.Raycast(t.transform.position + new Vector3(0, 10, 0), -Vector3.up, 100.0f, lm)) { mov.isEmpty = false; mov.piece = this; mov.tile = t; return(true); } } return(false); }
/* * fill a table with movements if the piece could kill the player in the next movement * Ex, {true, false, true}, this piece can kill the player if stay in the same tile or if it moves 2 tiles * array is iniciated by the function */ public void CanKillPlayerInHisNextMove(ref List <IAMovement.Movement>[] array) { LayerMask[] lm = new LayerMask[] { LayerMask.GetMask("Player"), LayerMask.GetMask("OneMove"), LayerMask.GetMask("TwoMove") }; foreach (Tile t in GetPosibleMovements()) { for (int i = 0; i < 3; i++) { if (Physics.Raycast(t.transform.position + new Vector3(0, 10, 0), -Vector3.up, 100.0f, lm[i])) { IAMovement.Movement aux = new IAMovement.Movement(); aux.isEmpty = false; aux.tile = t; aux.piece = this; array[i].Add(aux); } } } }
public override bool CanThreatInAMov(out IAMovement.Movement mov, int x, int y) { mov = new IAMovement.Movement(); if (_y != player.y) { Tile t = CheckExistTile(x, _y); if (t && !t.piece) { mov.piece = this; mov.tile = t; mov.isEmpty = false; return(true); } return(false); } else { return(false); } }
//Can threat the (x,y) tile in a mov, and return the mov that does it public virtual bool CanThreatInAMov(out IAMovement.Movement mov, int x, int y) { mov = new IAMovement.Movement(); Tile[] tiles = GetPosibleMovementsNoPlayerColumn(); foreach (Tile t in tiles) { if (CanGoToFrom(t.x, t.y, x, y)) { if (!t.piece) { mov.isEmpty = false; mov.piece = this; mov.tile = t; return(true); } } } return(false); }