Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
How to use chessboard positions in an if-else statement for chessboard.js

I am trying to create a function that uses an if-statement to check if a chessboard is in a specific position (this one I am using start) using the chessboard.js library

I tried using this code that compares the board's position property to the position I want using the object and FEN string but both doesn't work.

  if (board.position == {a1: "wR", a2: "wP", a7: "bP", , a8: "bR", b1: "wN", b2: "wP", b7: "bP", b8: "bN", c1: "wB", c2: "wP", c7: "bP", c8: "bB", d1: "wQ", d2: "wP", d7: "bP", d8: "bQ", e1: "wK", e2: "wP", e7: "bP", e8: "bK", f1: "wB", f2: "wP", f7: "bP", f8: "bB", g1: "wN", g2: "wP", g7: "bP", g8: "bN", h1: "wR", h2: "wP", h7: "bP", h8: "bR") {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');
   if (board.position == 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR') {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');

I even tried comparing it to 'start'

   if (board.position == 'start') {
    alert('The board is in the start position');
  } else {
    alert('The board is not in the start position');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Based on the docs, board.position is a function. You want to compare against the output of that function, not the function itself:

if (board.position('fen') == 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR')

(Comparing objects for equality is more complicated; I'd suggest sticking with the FEN strings.)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda