Chess player: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 3 users not shown)
Line 14:
 
or use those components as part of a complete program, demonstrating your language's support for modularity.
 
 
=={{header|BASIC}}==
{{works with|QBasic}}
Line 21 ⟶ 19:
 
Encontrado en: http://www.petesqbsite.com/sections/express/issue23/Tut_QB_Chess.txt
<langsyntaxhighlight lang="qbasic">DEFINT A-Z
 
DECLARE SUB SQUARE (A, B, C)
Line 496 ⟶ 494:
PRINT MT$
COLOR 7, 0
END SUB</langsyntaxhighlight>
 
 
=={{header|Go}}==
There are a number of open source Chess programs written in Go on Github.
 
Rather than spend a lot of time trying to write my own (likely mediocre) program, I thought I'd simply post a link to [https://github.com/notnil/chess notnil/chess] which explains its various capabilities quite well. However, you need to look at the code itself to see that it can cope with all types of move including castling, ''en passant'' capture and promotion to a piece of the player's choice.
 
=={{header|Perl}}==
Primarily written to see if I could find all moves with one regex. The answer was "mostly", the main problem being
some moves require history (the current state of the board is not sufficient for castling and en passant).
I also wanted to try different methods of making moves. It does not play well, but then neither do I.
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 939 ⟶ 934:
then left click on the square the opponent's Pawn skipped over.
END
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Version 0.8.1+ contains demo\rosetta\chess.exw, a slightly cleaned-up copy of a 20-year old translation of TSCP.<br>
It isn't particularly good (though perhaps a reasonable starting point for something better), at over 1,600 lines it does not really bear any useful comparison to the lisp version, and is simply not worth posting on this site, especially in light of potential copyright issues.
 
=={{header|PicoLisp}}==
{{:Chess player/PicoLisp}}
 
=={{header|Python}}==
==={{libheader|pygame}}===
Line 963 ⟶ 955:
 
The computer may say some things that allude to the chess game in ''2001: A Space Odyssey'', by the way.
<langsyntaxhighlight lang="python"># Simple Python chess engine
# Computer plays Black
 
Line 1,015 ⟶ 1,007:
for yourmove in board.legal_moves:
board.push(yourmove)
if board.result() == "1-0": # Has White won? If so, avoid move.
board.pop()
moves[mymove] = -1000
break
v = Counter(board.fen().split()[0])
p = (9 * (v['q']-v['Q']) + 5 * (v['r']-v['R']) + 3 * (v['b']-v['B'])
Line 1,032 ⟶ 1,028:
 
print(f"Game finished, result is {board.result()}")
hal9000()</langsyntaxhighlight>
{{Output}} (in ASCII)
<pre>$ python3 simplechess.py
Line 1,096 ⟶ 1,092:
18.Ke2 Bxa1 19.Kd2 Qxf1 20.Kc2 Qxf2+ 21.Kb1 Qb2# 0-1
</pre>
 
=={{header|Wren}}==
{{trans|BASIC}}
{{libheader|Wren-traititerate}}
{{libheader|Wren-fmt}}
{{libheader|Wren-ioutil}}
{{libheader|Wren-str}}
<langsyntaxhighlight ecmascriptlang="wren">import "./traititerate" for Stepped
import "./fmt" for Fmt
import "./ioutil" for Input, Output
import "./str" for Str
 
var Board = List.filled(8, null)
Line 1,665 ⟶ 1,660:
}
 
Chess.start()</langsyntaxhighlight>
9,476

edits