npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jogo-da-velha-core

v0.0.3

Published

Core do jogo da velha

Downloads

7

Readme

jogo-da-velha-core

De modo geral uma matriz precisa ser passada e alguns conceitos devem ser levado em conta

A matriz é uma array corrido de 9 posições simbolizando a posição no tabuleiro seguindo a tabela:

[0][1][2]
[3][4][5]
[6][7][8]

Não existe X ou O e sim 1 ou 2 simbolizando player 1 e player 2 ocupado. Onde não tiver nem 1 nem 2 deve ser preenchido por null.

Methods

reconhecerVitoria(matriz) : int or null

Se 1, o player 1 ganhou, se 2 o player 2 ganhou, se null ninguém ganhou

reconhecerEmpate(matriz) : boolean

Se true, teve empate, se false, não teve

joga( matriz, player, nivel ) : int or null

Conforme o níve de dificuldade enviado faz uma jogada pensada ou randomica. Sendo 0 o mais fácil, e 3 o mais difícil. Se for zero é com certeza uma jogada randomica. Se for 4 com certeza é uma jogada pensada. Se for 2 tem 50% de chance de fazer uma jogada pensada; Se for 3 tem 75% de chance de fazer uma jogada pensada;

Ele efetua uma jogada para o player enviado, então player deve ser 1 ou 2, invertido do player real.

matriz do jogo atual deve ser sempre enviada novamente.

Exemplos

const JogoDaVelhaCore = require("./jogo-da-velha-core") ;

var matriz = [null, null, null, null, null, null, null, null, null];

let core = new JogoDaVelhaCore() ;
let humanPlayer = 2 ;
let computerPlayer = 1;

var jogadaEscolhida = core.joga(matriz, computerPlayer, 3) ;
//note que é você quem tem que setar na matriz a jogada
matriz[jogadaEscolhida] = computerPlayer ;
//nesse exemplo estou colocando o computador pra jogar contra ele mesmo
jogadaEscolhida = core.joga(matriz, humanPlayer, 3) ;
matriz[jogadaEscolhida] = humanPlayer ;