TetrisBot: Better shot heuristics.

This commit is contained in:
2019-11-08 02:07:33 +01:00
parent 629ad33767
commit 64d7c9531b

View File

@@ -171,29 +171,28 @@ namespace VAR.ScreenAutomation.Bots
maxHeightWeight: -0.25); maxHeightWeight: -0.25);
} }
private bool _canShot = true; private const int ShowCooldownFrames = 2;
private int _lastShotShapeY = 0; private int _shotCooldown = ShowCooldownFrames;
private DateTime _lastShotDateTime;
public string ResponseKeys() public string ResponseKeys()
{ {
if (_shapeFound == false) { return string.Empty; } if (_shapeFound == false) { return string.Empty; }
if (_canShot == false && (_shapeY < _lastShotShapeY || _lastShotDateTime.AddMilliseconds(500) < DateTime.UtcNow))
{
_canShot = true;
}
if (_bestRotation == 0 && _bestXOffset == 0 && _bestEvaluation > double.MinValue) if (_bestRotation == 0 && _bestXOffset == 0 && _bestEvaluation > double.MinValue)
{ {
if (_canShot) if (_shotCooldown <= 0)
{ {
_canShot = false; _shotCooldown = ShowCooldownFrames;
_lastShotShapeY = _shapeY;
_lastShotDateTime = DateTime.UtcNow;
return " "; return " ";
} }
else
{
_shotCooldown--;
return string.Empty;
} }
}
_shotCooldown = ShowCooldownFrames;
if (_bestRotation != 0 && _bestXOffset < 0) { return "{UP}{LEFT}"; } if (_bestRotation != 0 && _bestXOffset < 0) { return "{UP}{LEFT}"; }
if (_bestRotation != 0 && _bestXOffset > 0) { return "{UP}{RIGHT}"; } if (_bestRotation != 0 && _bestXOffset > 0) { return "{UP}{RIGHT}"; }