This commit is contained in:
LadyEbony 2020-08-22 00:35:10 -07:00
commit 77c597498f
3 changed files with 76 additions and 4 deletions

View File

@ -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;
@ -65,6 +67,11 @@ public class GameBoard : EntityBase, IAutoSerialize, IAutoDeserialize {
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;
} else { } else {
@ -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)

View File

@ -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;
} }
@ -36,7 +39,9 @@ public class GameBoardInstance : MonoBehaviour {
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;
} }

View File

@ -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);