Methods
battle(player1, player2) → {Object}
This function is the battle field for the two players, it devises the logic for the players to target
each other turn by turn.
Parameters:
| Name | Type | Description |
|---|---|---|
player1 |
Object | : Player class |
player2 |
Object | : Player Class |
Returns:
winner: Player
- Type
- Object
fileReader(filePath, testStream) → {Promise}
This function would read file from a path line by line and populate the filecontent
object for further processing
Parameters:
| Name | Type | Description |
|---|---|---|
filePath |
string | |
testStream |
Readable | : sole purpose of this stream is for testing |
- Source:
Returns:
this would resolve when all of the content is read from the file
- Type
- Promise
parseCoordinates(coordinates) → {Array}
Helper method to parse coordinates, this would parse the character on its ascii value
Parameters:
| Name | Type | Description |
|---|---|---|
coordinates |
string | : these are the coordinates inside the player area. i.e. "A1" |
- Source:
Returns:
It returns the parsed xand y coordinates
- Type
- Array
validateArgs(fileContents) → {Object}
This function would validate the filecontents on the basis of pre-defined business rules
Rules :
1 <= Width of Battle area (M’) <= 9,
A <= Height of Battle area (N’) <= Z
1 <= Number of battleships <= M’ * N’
Type of ship = {‘P’, ‘Q’}
1 <= Width of battleship <= M’
A <= Height of battleship <= N
1 <= X coordinate of ship <= M’
A <= Y coordinate of ship <= N’
Parameters:
| Name | Type | Description |
|---|---|---|
fileContents |
Object |
- Source:
Returns:
ValidatedArgs : This would the object of validated filecontents
- Type
- Object