AI starts up automatically, special tiles are in
This commit is contained in:
parent
586098b3cf
commit
e7ee38dd1e
|
@ -50,6 +50,8 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
// Tile timing
|
// Tile timing
|
||||||
private int TilesUntilActivator = 3;
|
private int TilesUntilActivator = 3;
|
||||||
int nextActivator = -1;
|
int nextActivator = -1;
|
||||||
|
private int ActivatorsUntilSpecial = 10;
|
||||||
|
int nextSpecial = -1;
|
||||||
|
|
||||||
public float nextRootX = -1, nextRootY = 12;
|
public float nextRootX = -1, nextRootY = 12;
|
||||||
|
|
||||||
|
@ -64,6 +66,11 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
activator = TileInfo.CreateRandomActivatorTile();
|
activator = TileInfo.CreateRandomActivatorTile();
|
||||||
|
|
||||||
lastActivatorColor = activator.color;
|
lastActivatorColor = activator.color;
|
||||||
|
|
||||||
|
if (++nextSpecial >= ActivatorsUntilSpecial) {
|
||||||
|
nextSpecial = 0;
|
||||||
|
activator.kind = TileKind.Special;
|
||||||
|
}
|
||||||
|
|
||||||
if (Random.value > 0.5f) {
|
if (Random.value > 0.5f) {
|
||||||
pair.left = activator;
|
pair.left = activator;
|
||||||
|
@ -108,8 +115,9 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
case DelayState.Collapse:
|
case DelayState.Collapse:
|
||||||
if (timeInState > airCollapseTime) {
|
if (timeInState > airCollapseTime) {
|
||||||
board = Collapse(board); // Remove air
|
board = Collapse(board); // Remove air
|
||||||
|
board = SpecialActivation(board, out bool didSpecial);
|
||||||
board = ActivateOnce(board, out bool didActivate);
|
board = ActivateOnce(board, out bool didActivate);
|
||||||
if (didActivate) {
|
if (didActivate || didSpecial) {
|
||||||
delayState = DelayState.Combo;
|
delayState = DelayState.Combo;
|
||||||
++Combo;
|
++Combo;
|
||||||
} else {
|
} else {
|
||||||
|
@ -459,6 +467,48 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Activate all special tiles
|
||||||
|
BoardState SpecialActivation(BoardState bs, out bool didActivate) {
|
||||||
|
|
||||||
|
didActivate = false;
|
||||||
|
//return bs; // Test short-circuit
|
||||||
|
|
||||||
|
for (int x = 0; x < bs.Count; ++x) {
|
||||||
|
var col = bs[x];
|
||||||
|
for (int y = 0; y < col.Count; ++y) {
|
||||||
|
var tile = col[y];
|
||||||
|
if (tile.kind == TileKind.Special) {
|
||||||
|
if (y > 0) {
|
||||||
|
// Get the color of the tile we are on top of
|
||||||
|
var under = col[y - 1];
|
||||||
|
tile.kind = TileKind.Activiting;
|
||||||
|
tile.color = under.color;
|
||||||
|
bs = ActivateAllColor(bs, under.color);
|
||||||
|
didActivate = true;
|
||||||
|
} else {
|
||||||
|
// Special tile is on the bottom, swap it to a random activating tile
|
||||||
|
tile = TileInfo.CreateRandomActivatorTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoardState ActivateAllColor(BoardState bs,TileColor tc) {
|
||||||
|
for (int x = 0; x < bs.Count; ++x) {
|
||||||
|
var col = bs[x];
|
||||||
|
for (int y = 0; y < col.Count; ++y) {
|
||||||
|
var tile = col[y];
|
||||||
|
if (tile.color == tc) {
|
||||||
|
tile.kind = TileKind.Activiting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
int CountActivations(BoardState bs) {
|
int CountActivations(BoardState bs) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
foreach(var col in bs) {
|
foreach(var col in bs) {
|
||||||
|
@ -620,12 +670,16 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
public void Setup(){
|
public void Setup(){
|
||||||
board = BoardStateExtension.Initialize();
|
board = BoardStateExtension.Initialize();
|
||||||
|
|
||||||
|
StopAllCoroutines(); // Murder all coroutines :'D
|
||||||
|
// This is to reset the AI
|
||||||
|
|
||||||
// Build the list of possible placements the AI may use
|
// Build the list of possible placements the AI may use
|
||||||
PossiblePlacements = GetAllPossibilities();
|
PossiblePlacements = GetAllPossibilities();
|
||||||
|
|
||||||
lastActivatorColor = TileInfo.CreateRandomActivatorTile().color;
|
lastActivatorColor = TileInfo.CreateRandomActivatorTile().color;
|
||||||
|
|
||||||
nextActivator = TilesUntilActivator;
|
nextActivator = TilesUntilActivator;
|
||||||
|
nextSpecial = ActivatorsUntilSpecial;
|
||||||
delayState = DelayState.None;
|
delayState = DelayState.None;
|
||||||
timeInState = 0;
|
timeInState = 0;
|
||||||
|
|
||||||
|
@ -690,6 +744,8 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
repeat = false;
|
repeat = false;
|
||||||
bs = Collapse(bs);
|
bs = Collapse(bs);
|
||||||
bs = Activate(bs);
|
bs = Activate(bs);
|
||||||
|
bs = SpecialActivation(bs, out bool didActivate);
|
||||||
|
|
||||||
var newActivations = CountActivations(bs);
|
var newActivations = CountActivations(bs);
|
||||||
if (newActivations > 0) {
|
if (newActivations > 0) {
|
||||||
comboLength += 1;
|
comboLength += 1;
|
||||||
|
@ -811,14 +867,21 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
|
||||||
}
|
}
|
||||||
|
|
||||||
[ContextMenu("Startup AI")]
|
[ContextMenu("Startup AI")]
|
||||||
public void StartAI() {
|
public void StartAIDefault() {
|
||||||
|
StartAI();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartAI(float thinkTime = 0.5f) {
|
||||||
AIEnabled = true;
|
AIEnabled = true;
|
||||||
|
AIMoveTime = thinkTime;
|
||||||
StartCoroutine(AIThink());
|
StartCoroutine(AIThink());
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AIEnabled = false;
|
public bool AIEnabled = false;
|
||||||
public float AIMoveTime = 0.5f;
|
public float AIMoveTime = 0.5f;
|
||||||
IEnumerator AIThink() {
|
IEnumerator AIThink() {
|
||||||
|
yield return null; // Wait a frame before trying any shit
|
||||||
|
|
||||||
int totalMoves = 0;
|
int totalMoves = 0;
|
||||||
while (delayState != DelayState.Loss) {
|
while (delayState != DelayState.Loss) {
|
||||||
if (!AIEnabled)
|
if (!AIEnabled)
|
||||||
|
|
|
@ -14,6 +14,9 @@ public class GameBoardInstance : MonoBehaviour {
|
||||||
public Sprite[] lit;
|
public Sprite[] lit;
|
||||||
public Sprite[] activators;
|
public Sprite[] activators;
|
||||||
|
|
||||||
|
[Header("AI difficulty, 0(easy)-3(hardest)")]
|
||||||
|
public int AIDifficulty = 1;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
@ -31,11 +34,13 @@ public class GameBoardInstance : MonoBehaviour {
|
||||||
player2.Setup();
|
player2.Setup();
|
||||||
} else {
|
} else {
|
||||||
player1.authorityID = -1;
|
player1.authorityID = -1;
|
||||||
player2.authorityID = -1;
|
player2.authorityID = -1;
|
||||||
|
|
||||||
player1.Setup();
|
player1.Setup();
|
||||||
player2.Setup();
|
player2.Setup();
|
||||||
}
|
|
||||||
|
player2.StartAI(new[] { 0.5f, 0.2f, 0.1f, 0f }[AIDifficulty]);
|
||||||
|
}
|
||||||
|
|
||||||
GameTransition.Instance.state = GameState.InGame;
|
GameTransition.Instance.state = GameState.InGame;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ public class TileRender : MonoBehaviour {
|
||||||
case TileKind.Activiting:
|
case TileKind.Activiting:
|
||||||
sprites = GameBoardInstance.instance.lit;
|
sprites = GameBoardInstance.instance.lit;
|
||||||
break;
|
break;
|
||||||
|
case TileKind.Special:
|
||||||
|
int timeSprite = (int)(Time.time * 4);
|
||||||
|
renderer.sprite = GameBoardInstance.instance.activators[timeSprite % 4];
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
sprites = null;
|
sprites = null;
|
||||||
Debug.LogErrorFormat(this.gameObject,"{0}, {1}, {2} not supported by tile display", tile.color, tile.kind, tile.counter);
|
Debug.LogErrorFormat(this.gameObject,"{0}, {1}, {2} not supported by tile display", tile.color, tile.kind, tile.counter);
|
||||||
|
|
Loading…
Reference in New Issue