winner-calc

v1.0.1arrow_drop_down
v1.0.1
v1.0.0
v0.0.3
v0.0.2
v0.0.1
STATUS
Passing
DOWNLOADS
209
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
862 B
check winner horizontal, vertical and diagonal
1 contributor
Install winner-calc as a package?
Copied
npm i @bit/joshk.tic-tac-toe-game.utils.winner-calc
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
No preview available
modifieddraft
No preview available
modifieddraft
chevron_left
chevron_right
utils/winnerCalc (
matrix:Array<Array.<string>>,
rowsNum:number,
colsNum:number,
numToWin:number,
lastRow:number,
lastCol:number
) : string

check winner horizontal, vertical and diagonal

Example
import winnerCalc from '@bit/joshk.tic-tac-toe-game.utils.winner-calc';

const matrix = [
  ['O', 'O', 'X'],
  ['O', 'X', ''],
  ['X', '', '']
];
const result = winnerCalc(matrix, 3, 3, 3, 0, 2);

export default result
Arguments
matrix: Array<Array.<string>>

2d array with X and O

rowsNum: number

number of rows

colsNum: number

number of columns

numToWin: number

the number of matching to win

lastRow: number

the row number of the square player click

lastCol: number

the column number of the square player click

Returns
string

return the winner, X or O or '' if no one win.

Test Summary

Winner check function should return draw

Pass

Winner check function should return no winner

Pass

Winner check function should return winner in horizontal first row

Pass

Winner check function should return winner in horizontal second row

Pass

Winner check function should return winner in horizontal third row

Pass

Winner check function should return winner in vertical fisrt row

Pass

Winner check function should return winner in vertical second row

Pass

Winner check function should return winner in vertical third row

Pass

Winner check function should return winner in diagonal bottom right - top left

Pass

Winner check function should return winner in diagonal bottom left - top right

Pass

Winner check function should return winner in diagonal

Pass
Help and resources