0.0.17 • Published 3 years ago

@lil_marcrock22/connect4-ai v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@lil_marcrock22/connect4-ai

Install

npm i @lil_marcrock22/connect4-ai

How to use (TypeScript)

interface Player {
	turn: number;
	id: string;
	morethings?: any;
}

const { Connect4AI } = require('@lil_marcrock22/connect4-ai'); 
const TheGame = new Connect4AI<Player>({ lengthArr: 6, columns: 7, necessaryToWin: 4 }, 
	[{ turn: 1, id: '123' }, { turn: 2, id: '456' }]//This is for <Game>.players
);
TheGame.createBoard();

How to use (JavaScript)

const { Connect4AI } = require('@lil_marcrock22/connect4-ai'); 
const TheGame = new Connect4AI({ lengthArr: 6, columns: 7, necessaryToWin: 4 }, 
	[{ turn: 1, id: '123' }, { turn: 2, id: '456' }]//This is for <Game>.players
);
TheGame.createBoard();
console.log(TheGame.map);
/*
{
	0: [{ key: 0, index: 0: column: 0 }, { key: 0, index: 1 column: 0 }, ...]
	1: [{ key: 0, index: 0: column: 1 }, { key: 0, index: 1 column: 1 }, ...],
	...
}
*/
const move = 5

if (TheGame.canPlay(move)) {
	TheGame.play(move);
	console.log(`${move} played :D`);
} else {
	console.error(`Cannot play ${move} D:`);
}
const difficulty = 'hard'; 
const played = TheGame.playAI(difficulty);//'easy' | 'medium' | 'hard'

console.log(`[AI]: column played ${played}`);

INFO

interface Move {
	key: number;
	index: number;
	column: number;
}

Properties and getters

PropertyType
playsnumber[]
__finishedboolean
winnernumber \| null
solutionMove[] \| null
lengthArrnumber
columnsnumber
_lastTurnnumber
startnumber
getter turnnumber
getter tieboolean
getter finishedboolean
getter arrayMove[][]

Methods

PropertyReturns
canPlay(number)boolean
private checkArr(Move[]){ encontrado: number; veces: number; solution: Move[]; }
createBoard(){ [x: number]: Move[] }
reset()this Connect4 \| Connect4AI
Just with Connect4AI playAI('easy' \| 'medium' \| 'hard')number
<!-- You lost the game -->
<!-- https://www.npmjs.com/package/connect4-ai -->
0.0.17

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago