Skip to content

Commit

Permalink
Inspection tuning for outcomes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kellan Wampler committed Feb 7, 2024
1 parent 63f49a9 commit d2402f7
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 228 deletions.
24 changes: 14 additions & 10 deletions python/fullcount/generation_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

from . import data

Distance0: data.OutcomeDistribution = (0, 0, 0, 4458, 1408, 126, 1008, 3000)
Distance0: data.OutcomeDistribution = (0, 0, 0, 1000, 3000, 1000, 5000, 0)

Distance1: data.OutcomeDistribution = (500, 0, 500, 3185, 1005, 90, 720, 4000)
Distance1: data.OutcomeDistribution = (0, 0, 2500, 2500, 2000, 500, 2500, 0)

Distance2: data.OutcomeDistribution = (1500, 0, 1500, 1910, 603, 55, 432, 4000)
Distance2: data.OutcomeDistribution = (
1000, 0, 3200, 3200, 1100, 200, 800, 500)

Distance3: data.OutcomeDistribution = (4500, 0, 1500, 736, 241, 23, 0, 3000)
Distance3: data.OutcomeDistribution = (4000, 0, 3000, 1500, 250, 0, 0, 1250)

Distance4: data.OutcomeDistribution = (6000, 0, 1000, 0, 0, 0, 0, 3000)
Distance4: data.OutcomeDistribution = (7000, 0, 2000, 0, 0, 0, 0, 1000)

DistanceGT4: data.OutcomeDistribution = (10000, 0, 0, 0, 0, 0, 0, 0)
DistanceGT4: data.OutcomeDistribution = (10_000, 0, 0, 0, 0, 0, 0, 0)


def result(
Expand Down Expand Up @@ -51,7 +52,7 @@ def result(
elif distance == 2:
distribution = Distance2
elif distance == 3:
distribution = Distance3
distribution = Distance3
elif distance == 4:
distribution = Distance4
elif distance > 4:
Expand Down Expand Up @@ -161,14 +162,16 @@ def handle_result(args: argparse.Namespace) -> None:
def handle_rollout(args: argparse.Namespace) -> None:
results = rollout(
args.num_samples,
data.PitchType(args.pitch_type) if args.pitch_type is not None else None,
data.PitchType(
args.pitch_type) if args.pitch_type is not None else None,
data.VerticalLocation(args.pitch_vertical)
if args.pitch_vertical is not None
else None,
data.HorizontalLocation(args.pitch_horizontal)
if args.pitch_horizontal is not None
else None,
data.SwingType(args.swing_type) if args.swing_type is not None else None,
data.SwingType(
args.swing_type) if args.swing_type is not None else None,
data.VerticalLocation(args.swing_vertical)
if args.swing_vertical is not None
else None,
Expand All @@ -185,7 +188,8 @@ def handle_rollout(args: argparse.Namespace) -> None:


def generate_cli() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Fullcount rules: Generation 1")
parser = argparse.ArgumentParser(
description="Fullcount rules: Generation 1")
parser.set_defaults(func=lambda _: parser.print_help())

subparsers = parser.add_subparsers()
Expand Down
23 changes: 18 additions & 5 deletions src/Fullcount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@ contract Fullcount is EIP712 {

uint256 public NumSessions;

uint256[8] public Distance0Distribution = [0, 0, 0, 4458, 1408, 126, 1008, 3000];
uint256[8] public Distance1Distribution = [500, 0, 500, 3185, 1005, 90, 720, 4000];
uint256[8] public Distance2Distribution = [1500, 0, 1500, 1910, 603, 55, 432, 4000];
uint256[8] public Distance3Distribution = [4500, 0, 1500, 736, 241, 23, 0, 3000];
uint256[8] public Distance4Distribution = [6000, 0, 1000, 0, 0, 0, 0, 3000];
// We want to strongly reward distance 0 swings.
// 10% chance of single, 30% chance of double, 10% chance of triple, 50% chance of home run
uint256[8] public Distance0Distribution = [0, 0, 0, 1000, 3000, 1000, 5000, 0];
// Distance 1 swings should also be mostly postive outcomes and have no negative outsomes (for batter)
// but considerably lower chances at big hits.
// 25% chamce of foul, 25% chance of single, 20% chance of double, 5% chance of triple, 25% chance of home run
uint256[8] public Distance1Distribution = [0, 0, 2500, 2500, 2000, 500, 2500, 0];
// Distance 2 swings should be half hits (mostly weaker) with some neutral and few negative outcomes
// 10% chance of strike, 32% chance of foul, 32% chance of single, 11% chance of double, 2% chance of triple,
// 8% chance of home run, 5% chance of out
uint256[8] public Distance2Distribution = [1000, 0, 3200, 3200, 1100, 200, 800, 500];
// Distance 3 swings should be mostly negative outcomes and little chance of big hits
// 40% chance of strike, 30% chance of foul, 15% chance of single, 2.5% chance of double, 12.5% chance of out
uint256[8] public Distance3Distribution = [4000, 0, 3000, 1500, 250, 0, 0, 1250];
// Distance 4 swings should be mostly strikes and have no positive outcomes (for batter)
// 70% chance of strike, 20% chance of foul, 10% chance of out
uint256[8] public Distance4Distribution = [7000, 0, 2000, 0, 0, 0, 0, 1000];
// Distance 5+ swings should all be strikes
uint256[8] public DistanceGT4Distribution = [10_000, 0, 0, 0, 0, 0, 0, 0];

// Session ID => session state
Expand Down
38 changes: 21 additions & 17 deletions test/AtBats.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,15 @@ contract FullcountTest_ballsAndStrikes is FullcountAtBatTest {

function _foulSession(uint256 sessionID) internal {
// From Resolutinos test file

Pitch memory pitch = Pitch(
8_896_391_875_205_613_932_298_229_962_938_938_694_841_002_446_457_628_837_939_997_515_662_919_318_336,
PitchSpeed.Fast,
VerticalLocation.Middle,
76_272_677_889_733_487_807_869_088_975_394_561_199_007_238_211_299_295_369_669_345_782_657_832_457_462,
PitchSpeed.Slow,
VerticalLocation.HighBall,
HorizontalLocation.OutsideStrike
);
Swing memory swing = Swing(19_734, SwingType.Power, VerticalLocation.HighStrike, HorizontalLocation.Middle);

Swing memory swing = Swing(5027, SwingType.Contact, VerticalLocation.HighBall, HorizontalLocation.OutsideStrike);

_commitPitch(sessionID, player1, player1PrivateKey, pitch);
_commitSwing(sessionID, player2, player2PrivateKey, swing);
Expand Down Expand Up @@ -795,12 +797,13 @@ contract FullcountTest_ballsAndStrikes is FullcountAtBatTest {

// Generates a double
Pitch memory pitch = Pitch(
57_761_167_149_431_627_567_619_636_552_548_080_695_738_090_550_175_245_247_314_135_192_585_439_073_298,
PitchSpeed.Slow,
VerticalLocation.LowBall,
HorizontalLocation.OutsideStrike
115_501_419_915_073_027_201_528_450_984_807_047_638_958_490_173_387_813_223_494_386_604_734_350_200_751,
PitchSpeed.Fast,
VerticalLocation.Middle,
HorizontalLocation.Middle
);
Swing memory swing = Swing(10_508, SwingType.Power, VerticalLocation.LowBall, HorizontalLocation.OutsideBall);

Swing memory swing = Swing(4574, SwingType.Contact, VerticalLocation.HighBall, HorizontalLocation.OutsideStrike);

_commitPitch(sixthSessionID, player1, player1PrivateKey, pitch);
_commitSwing(sixthSessionID, player2, player2PrivateKey, swing);
Expand Down Expand Up @@ -881,7 +884,7 @@ contract FullcountTest_ballsAndStrikes is FullcountAtBatTest {
assertEq(uint256(atBat.outcome), uint256(AtBatOutcome.InProgress));
}

function test_atBatProgress_events() public {
function test_at_bat_progress_events() public {
AtBat memory atBat = game.getAtBat(AtBatID);
assertEq(atBat.pitcherNFT.nftAddress, address(characterNFTs));
assertEq(atBat.pitcherNFT.tokenID, PitcherTokenID);
Expand Down Expand Up @@ -1026,17 +1029,18 @@ contract FullcountTest_ballsAndStrikes is FullcountAtBatTest {

nextSessionID = game.AtBatSessions(AtBatID, 5);

// Generates a home run
Pitch memory hrPitch = Pitch(
63_640_271_245_765_366_210_780_587_460_610_203_501_690_580_269_930_603_495_014_854_898_867_107_880_639,
PitchSpeed.Slow,
VerticalLocation.HighStrike,
HorizontalLocation.OutsideStrike
80_491_828_288_466_500_398_500_201_838_979_874_564_536_822_010_908_142_391_208_468_039_821_070_678_148,
PitchSpeed.Fast,
VerticalLocation.Middle,
HorizontalLocation.InsideStrike
);

_commitPitch(nextSessionID, player1, player1PrivateKey, hrPitch);

Swing memory hrSwing =
Swing(1982, SwingType.Contact, VerticalLocation.HighStrike, HorizontalLocation.OutsideStrike);
Swing(32_155, SwingType.Power, VerticalLocation.LowStrike, HorizontalLocation.InsideStrike);

_commitPitch(nextSessionID, player1, player1PrivateKey, hrPitch);

_commitSwing(nextSessionID, player2, player2PrivateKey, hrSwing);

Expand Down
Loading

0 comments on commit d2402f7

Please sign in to comment.