# [BaseBotGame] 2022-10-03 Pitcher ### Object Pitcher pitch - Input: Pitcher - Output: pitch position and if it's a strike ### Behavior Pitcher pitch a ball randomly locate at a zone. Then, the strike zone object determines whether it's a strike or not. ### Algorithm Basic Class: 1. `Grid` object has `x`, `y` coordinate 2. `Pitch` object stands for a pitching result including position represented by `Grid` Pitch: 1. `BaseballPlayer` has `name`, `number`, and `fieldPosition` 2. `Pitcher` inherits from `BaseballPlayer` and extend `pitch` method 3. `pitch` method return a random position ```c++ const int max_x = 5; const int max_y = 5; pitch.pos.x = rand() % max_x pitch.pos.y = rand() % max_y ``` Strike Zone: | | | | | | |---|---|---|---|---| | x | x | x | x | x | | x | o | o | o | x | | x | o | o | o | x | | x | o | o | o | x | | **x** | x | x | x | x | 1. The origin locates at the left bottom grid(bold x) and goes to right and top. 2. `StrikeZone` object has 2 `Grid`: `leftBot` and `rightTop` form a rectangular. 3. `isStrike` method takes a `Pitch` as input and if the position of pitch is in the rectangular it's a strike ```c++ bool isSstrke = leftBot.x <= pitch.pos.x <= rightTop.x && leftBot.y <= pitch.pos.y <= rightTop.y; ```