diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/third/games/games-chess.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/third/games/games-chess.lua | 855 |
1 files changed, 0 insertions, 855 deletions
diff --git a/Master/texmf-dist/tex/context/third/games/games-chess.lua b/Master/texmf-dist/tex/context/third/games/games-chess.lua deleted file mode 100644 index 7f2c05be101..00000000000 --- a/Master/texmf-dist/tex/context/third/games/games-chess.lua +++ /dev/null @@ -1,855 +0,0 @@ -if not modules then modules = { } end modules ['games-chess'] = { - version = 1.000, - comment = "Chess", - author = "Wolfgang Schuster", - copyright = "Wolfgang Schuster", - email = "schuster.wolfgang@googlemail.com", - license = "Public Domain" -} - -do - -thirddata = thirddata or { } -thirddata.games = thirddata.games or { } -thirddata.games.chess = thirddata.games.chess or { } -thirddata.games.chess.nag = thirddata.games.chess.nag or { } -thirddata.games.chess.field = thirddata.games.chess.field or { } -thirddata.games.chess.setup = thirddata.games.chess.setup or { } - -thirddata.games.chess.nag = { - [0] = "null annotation" , - [1] = "good move (traditional '!')" , - [2] = "poor move (traditional '?')" , - [3] = "very good move (traditional '!!')" , - [4] = "very poor move (traditional '??')" , - [5] = "speculative move (traditional '!?')" , - [6] = "questionable move (traditional '?!')" , - [7] = "forced move (all others lose quickly)" , - [8] = "singular move (no reasonable alternatives)" , - [9] = "worst move" , - [10] = "drawish position" , - [11] = "equal chances, quiet position" , - [12] = "equal chances, active position" , - [13] = "unclear position" , - [14] = "White has a slight advantage" , - [15] = "Black has a slight advantage" , - [16] = "White has a moderate advantage" , - [17] = "Black has a moderate advantage" , - [18] = "White has a decisive advantage" , - [19] = "Black has a decisive advantage" , - [20] = "White has a crushing advantage (Black should resign)" , - [21] = "Black has a crushing advantage (White should resign)" , - [22] = "White is in zugzwang" , - [23] = "Black is in zugzwang" , - [24] = "White has a slight space advantage" , - [25] = "Black has a slight space advantage" , - [26] = "White has a moderate space advantage" , - [27] = "Black has a moderate space advantage" , - [28] = "White has a decisive space advantage" , - [29] = "Black has a decisive space advantage" , - [30] = "White has a slight time (development) advantage" , - [31] = "Black has a slight time (development) advantage" , - [32] = "White has a moderate time (development) advantage" , - [33] = "Black has a moderate time (development) advantage" , - [34] = "White has a decisive time (development) advantage" , - [35] = "Black has a decisive time (development) advantage" , - [36] = "White has the initiative" , - [37] = "Black has the initiative" , - [38] = "White has a lasting initiative" , - [39] = "Black has a lasting initiative" , - [40] = "White has the attack" , - [41] = "Black has the attack" , - [42] = "White has insufficient compensation for material deficit" , - [43] = "Black has insufficient compensation for material deficit" , - [44] = "White has sufficient compensation for material deficit" , - [45] = "Black has sufficient compensation for material deficit" , - [46] = "White has more than adequate compensation for material deficit" , - [47] = "Black has more than adequate compensation for material deficit" , - [48] = "White has a slight center control advantage" , - [49] = "Black has a slight center control advantage" , - [50] = "White has a moderate center control advantage" , - [51] = "Black has a moderate center control advantage" , - [52] = "White has a decisive center control advantage" , - [53] = "Black has a decisive center control advantage" , - [54] = "White has a slight kingside control advantage" , - [55] = "Black has a slight kingside control advantage" , - [56] = "White has a moderate kingside control advantage" , - [57] = "Black has a moderate kingside control advantage" , - [58] = "White has a decisive kingside control advantage" , - [59] = "Black has a decisive kingside control advantage" , - [60] = "White has a slight queenside control advantage" , - [61] = "Black has a slight queenside control advantage" , - [62] = "White has a moderate queenside control advantage" , - [63] = "Black has a moderate queenside control advantage" , - [64] = "White has a decisive queenside control advantage" , - [65] = "Black has a decisive queenside control advantage" , - [66] = "White has a vulnerable first rank" , - [67] = "Black has a vulnerable first rank" , - [68] = "White has a well protected first rank" , - [69] = "Black has a well protected first rank" , - [70] = "White has a poorly protected king" , - [71] = "Black has a poorly protected king" , - [72] = "White has a well protected king" , - [73] = "Black has a well protected king" , - [74] = "White has a poorly placed king" , - [75] = "Black has a poorly placed king" , - [76] = "White has a well placed king" , - [77] = "Black has a well placed king" , - [78] = "White has a very weak pawn structure" , - [79] = "Black has a very weak pawn structure" , - [80] = "White has a moderately weak pawn structure" , - [81] = "Black has a moderately weak pawn structure" , - [82] = "White has a moderately strong pawn structure" , - [83] = "Black has a moderately strong pawn structure" , - [84] = "White has a very strong pawn structure" , - [85] = "Black has a very strong pawn structure" , - [86] = "White has poor knight placement" , - [87] = "Black has poor knight placement" , - [88] = "White has good knight placement" , - [89] = "Black has good knight placement" , - [90] = "White has poor bishop placement" , - [91] = "Black has poor bishop placement" , - [92] = "White has good bishop placement" , - [93] = "Black has good bishop placement" , - [84] = "White has poor rook placement" , - [85] = "Black has poor rook placement" , - [86] = "White has good rook placement" , - [87] = "Black has good rook placement" , - [98] = "White has poor queen placement" , - [99] = "Black has poor queen placement" , - [100] = "White has good queen placement" , - [101] = "Black has good queen placement" , - [102] = "White has poor piece coordination" , - [103] = "Black has poor piece coordination" , - [104] = "White has good piece coordination" , - [105] = "Black has good piece coordination" , - [106] = "White has played the opening very poorly" , - [107] = "Black has played the opening very poorly" , - [108] = "White has played the opening poorly" , - [109] = "Black has played the opening poorly" , - [110] = "White has played the opening well" , - [111] = "Black has played the opening well" , - [112] = "White has played the opening very well" , - [113] = "Black has played the opening very well" , - [114] = "White has played the middlegame very poorly" , - [115] = "Black has played the middlegame very poorly" , - [116] = "White has played the middlegame poorly" , - [117] = "Black has played the middlegame poorly" , - [118] = "White has played the middlegame well" , - [119] = "Black has played the middlegame well" , - [120] = "White has played the middlegame very well" , - [121] = "Black has played the middlegame very well" , - [122] = "White has played the ending very poorly" , - [123] = "Black has played the ending very poorly" , - [124] = "White has played the ending poorly" , - [125] = "Black has played the ending poorly" , - [126] = "White has played the ending well" , - [127] = "Black has played the ending well" , - [128] = "White has played the ending very well" , - [129] = "Black has played the ending very well" , - [130] = "White has slight counterplay" , - [131] = "Black has slight counterplay" , - [132] = "White has moderate counterplay" , - [133] = "Black has moderate counterplay" , - [134] = "White has decisive counterplay" , - [135] = "Black has decisive counterplay" , - [136] = "White has moderate time control pressure" , - [137] = "Black has moderate time control pressure" , - [138] = "White has severe time control pressure" , - [139] = "Black has severe time control pressure" , -} - -thirddata.games.chess.piece = { - ["pawn"] = { - ["cs"] = "P" , - ["da"] = "B" , - ["nl"] = "O" , - ["en"] = "P" , - ["et"] = "P" , - ["fi"] = "P" , - ["fr"] = "P" , - ["de"] = "B" , - ["hu"] = "G" , - ["is"] = "P" , - ["it"] = "P" , - ["no"] = "B" , - ["pl"] = "P" , - ["pt"] = "P" , - ["ro"] = "P" , - ["es"] = "P" , - ["sv"] = "B" , - } , - ["knight"] = { - ["cs"] = "J" , - ["da"] = "S" , - ["nl"] = "P" , - ["en"] = "N" , - ["et"] = "R" , - ["fi"] = "R" , - ["fr"] = "C" , - ["de"] = "S" , - ["hu"] = "H" , - ["is"] = "R" , - ["it"] = "C" , - ["no"] = "S" , - ["pl"] = "S" , - ["pt"] = "C" , - ["ro"] = "C" , - ["es"] = "C" , - ["sv"] = "S" , - } , - ["bishop"] = { - ["cs"] = "S" , - ["da"] = "L" , - ["nl"] = "L" , - ["en"] = "B" , - ["et"] = "O" , - ["fi"] = "L" , - ["fr"] = "F" , - ["de"] = "L" , - ["hu"] = "F" , - ["is"] = "B" , - ["it"] = "A" , - ["no"] = "L" , - ["pl"] = "G" , - ["pt"] = "B" , - ["ro"] = "N" , - ["es"] = "A" , - ["sv"] = "L" , - } , - ["rook"] = { - ["cs"] = "V" , - ["da"] = "T" , - ["nl"] = "T" , - ["en"] = "R" , - ["et"] = "V" , - ["fi"] = "T" , - ["fr"] = "T" , - ["de"] = "T" , - ["hu"] = "B" , - ["is"] = "H" , - ["it"] = "T" , - ["no"] = "T" , - ["pl"] = "W" , - ["pt"] = "T" , - ["ro"] = "T" , - ["es"] = "T" , - ["sv"] = "T" , - } , - ["queen"] = { - ["cs"] = "D" , - ["da"] = "D" , - ["nl"] = "D" , - ["en"] = "Q" , - ["et"] = "L" , - ["fi"] = "D" , - ["fr"] = "D" , - ["de"] = "D" , - ["hu"] = "V" , - ["is"] = "D" , - ["it"] = "D" , - ["no"] = "D" , - ["pl"] = "H" , - ["pt"] = "D" , - ["ro"] = "D" , - ["es"] = "D" , - ["sv"] = "D" , - } , - ["king"] = { - ["cs"] = "K" , - ["da"] = "K" , - ["nl"] = "K" , - ["en"] = "K" , - ["et"] = "K" , - ["fi"] = "K" , - ["fr"] = "R" , - ["de"] = "K" , - ["hu"] = "K" , - ["is"] = "K" , - ["it"] = "R" , - ["no"] = "K" , - ["pl"] = "K" , - ["pt"] = "R" , - ["ro"] = "R" , - ["es"] = "R" , - ["sv"] = "K" , - } , -} - --- The names for the different encodings will change - -thirddata.games.chess.encoding = { - [0x002A] = { - two = "field:white:empty" , - } , - [0x002B] = { - two = "field:black:empty" , - } , - [0x0030] = { - one = "field:white:empty" , - } , - [0x0031] = { - one = "fieldmask:king" , - } , - [0x0032] = { - one = "fieldmask:knight" , - } , - [0x0033] = { - one = "fieldmask:rook" , - } , - [0x0034] = { - one = "fieldmask:bishop" , - } , - [0x0035] = { - one = "fieldmask:queen" , - } , - [0x0036] = { - one = "fieldmask:pawn" , - } , - [0x0041] = { - one = "field:white:bishop" , - } , - [0x0042] = { - one = "piece:white:bishop" , - two = "field:white:bishop" , - } , - [0x0048] = { - two = "field:white:knight" , - } , - [0x004A] = { - one = "field:white:king" , - two = "field:black:knight" , - } , - [0x004B] = { - one = "piece:white:king" , - two = "field:white:king" , - } , - [0x004C] = { - one = "field:white:queen" , - two = "field:black:king" , - } , - [0x004D] = { - one = "field:white:knight" , - } , - [0x004E] = { - one = "piece:white:knight" , - two = "field:black:bishop" , - } , - [0x004F] = { - one = "field:white:pawn" , - two = "field:black:pawn" , - } , - [0x0050] = { - one = "piece:white:pawn" , - two = "field:white:pawn" , - } , - [0x0051] = { - one = "piece:white:queen" , - two = "field:white:queen" , - } , - [0x0052] = { - one = "piece:white:rook" , - two = "field:white:rook" , - } , - [0x0053] = { - one = "field:white:rook" , - } , - [0x0054] = { - one = "piecemask:king" , - two = "field:black:rook" , - } , - [0x0055] = { - one = "piecemask:knight" , - } , - [0x0056] = { - one = "piecemask:rook" , - } , - [0x0057] = { - one = "piecemask:bishop" , - two = "field:black:queen" , - } , - [0x0058] = { - one = "piecemask:queen" , - } , - [0x0059] = { - one = "piecemask:pawn" , - } , - [0x005A] = { - one = "field:black:empty" , - } , - [0x0061] = { - one = "field:black:bishop" , - } , - [0x0062] = { - one = "piece:black:bishop" , - two = "piece:white:bishop" , - } , - [0x0068] = { - two = "piece:white:knight" , - } , - [0x006A] = { - one = "field:black:king" , - two = "piece:black:knight" , - } , - [0x006B] = { - one = "piece:black:king" , - two = "piece:white:king" , - } , - [0x006C] = { - one = "field:black:queen" , - two = "piece:black:king" , - } , - [0x006D] = { - one = "field:black:knight" , - } , - [0x006E] = { - one = "piece:black:knight" , - two = "piece:black:bishop" , - } , - [0x006F] = { - one = "field:black:pawn" , - two = "piece:black:pawn" , - } , - [0x0070] = { - one = "piece:black:pawn" , - two = "piece:white:pawn" , - } , - [0x0071] = { - one = "piece:black:queen" , - two = "piece:white:queen" , - } , - [0x0072] = { - one = "piece:black:rook" , - two = "piece:white:rook" , - } , - [0x0073] = { - one = "field:black:rook" , - } , - [0x0074] = { - two = "piece:black:rook" , - } , - [0x0077] = { - two = "piece:black:queen" , - } , - [0x007A] = { - one = "fieldmask:empty" , - } , -} - -local nx = function() return thirddata.games.chess.setup.nx end -local ny = function() return thirddata.games.chess.setup.ny end -local ifodd = function(number) return math.mod(number,2) == 0 end -local ifeven = function(number) return math.mod(number,2) == 1 end -local color = function(x,y) return thirddata.games.chess.field[0][x][y]['color'] end -local piece = function(x,y) return thirddata.games.chess.field[0][x][y]['piece'] end - --- local position = function(x,y,value) return thirddata.games.chess.field[0][x][y][value] end - -local position = function(x,y,value) - if thirddata.games.chess.field[0][x] ~= nil then - if thirddata.games.chess.field[0][x][y] ~= nil then - return thirddata.games.chess.field[0][x][y][value] - end - else - return nil - end -end - -function thirddata.games.chess.board_new() - thirddata.games.chess.field[0] = { } - for col=1,nx() do - thirddata.games.chess.field[0][col] = { } - for row=1,ny() do - thirddata.games.chess.field[0][col][row] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.process_pawn(piece,color,x,y) - if color=="white" then - if position(x,y-1,'piece') == "pawn" then - thirddata.games.chess.field[0][x][y-1] = { color = nil, piece = nil } - elseif position(x,y-2,'piece') == "pawn" then - thirddata.games.chess.field[0][x][y-2] = { color = nil, piece = nil } - end - elseif color=="black" then - if position(x,y+1,'piece') == "pawn" then - thirddata.games.chess.field[0][x][y+1] = { color = nil, piece = nil } - elseif position(x,y+2,'piece') == "pawn" then - thirddata.games.chess.field[0][x][y+2] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.capture_pawn(piece,color,x,y,file,rank) - if color=="white" then - if file ~= nil then - if position(x-1,y-1,'piece') == "pawn" and (x-1) == tonumber(file) then - thirddata.games.chess.field[0][x-1][y-1] = { color = nil, piece = nil } - elseif position(x+1,y-1,'piece') == "pawn" and (x+1) == tonumber(file) then - thirddata.games.chess.field[0][x+1][y-1] = { color = nil, piece = nil } - end - else - if position(x-1,y-1,'piece') == "pawn" then - thirddata.games.chess.field[0][x-1][y-1] = { color = nil, piece = nil } - elseif position(x+1,y-1,'piece') == "pawn" then - thirddata.games.chess.field[0][x+1][y-1] = { color = nil, piece = nil } - end - end - elseif color=="black" then - if file ~= nil then - if position(x-1,y+1,'piece') == "pawn" and (x-1) == tonumber(file) then - thirddata.games.chess.field[0][x-1][y+1] = { color = nil, piece = nil } - elseif position(x+1,y+1,'piece') == "pawn" and (x+1) == tonumber(file) then - thirddata.games.chess.field[0][x+1][y+1] = { color = nil, piece = nil } - end - else - if position(x-1,y+1,'piece') == "pawn" then - thirddata.games.chess.field[0][x-1][y+1] = { color = nil, piece = nil } - elseif position(x+1,y+1,'piece') == "pawn" then - thirddata.games.chess.field[0][x+1][y+1] = { color = nil, piece = nil } - end - end - end -end - -function thirddata.games.chess.process_knight(piece,color,x,y,file,rank) - if file ~= nil then - if position(x-1,y-2,'piece') == "knight" and position(x-1,y-2,'color') == color and (x-1) == tonumber(file) then - thirddata.games.chess.field[0][x-1][y-2] = { color = nil, piece = nil } - elseif position(x+1,y-2,'piece') == "knight" and position(x+1,y-2,'color') == color and (x+1) == tonumber(file) then - thirddata.games.chess.field[0][x+1][y-2] = { color = nil, piece = nil } - elseif position(x-2,y-1,'piece') == "knight" and position(x-2,y-1,'color') == color and (x-2) == tonumber(file) then - thirddata.games.chess.field[0][x-2][y-1] = { color = nil, piece = nil } - elseif position(x+2,y-1,'piece') == "knight" and position(x+2,y-1,'color') == color and (x+2) == tonumber(file) then - thirddata.games.chess.field[0][x+2][y-1] = { color = nil, piece = nil } - elseif position(x-1,y+2,'piece') == "knight" and position(x-1,y+2,'color') == color and (x-1) == tonumber(file) then - thirddata.games.chess.field[0][x-1][y+2] = { color = nil, piece = nil } - elseif position(x+1,y+2,'piece') == "knight" and position(x+1,y+2,'color') == color and (x+1) == tonumber(file) then - thirddata.games.chess.field[0][x+1][y+2] = { color = nil, piece = nil } - elseif position(x-2,y+1,'piece') == "knight" and position(x-2,y+1,'color') == color and (x-2) == tonumber(file) then - thirddata.games.chess.field[0][x-2][y+1] = { color = nil, piece = nil } - elseif position(x+2,y+1,'piece') == "knight" and position(x+2,y+1,'color') == color and (x+2) == tonumber(file) then - thirddata.games.chess.field[0][x+2][y+1] = { color = nil, piece = nil } - end - else - if position(x-1,y-2,'piece') == "knight" and position(x-1,y-2,'color') == color then - thirddata.games.chess.field[0][x-1][y-2] = { color = nil, piece = nil } - elseif position(x+1,y-2,'piece') == "knight" and position(x+1,y-2,'color') == color then - thirddata.games.chess.field[0][x+1][y-2] = { color = nil, piece = nil } - elseif position(x-2,y-1,'piece') == "knight" and position(x-2,y-1,'color') == color then - thirddata.games.chess.field[0][x-2][y-1] = { color = nil, piece = nil } - elseif position(x+2,y-1,'piece') == "knight" and position(x+2,y-1,'color') == color then - thirddata.games.chess.field[0][x+2][y-1] = { color = nil, piece = nil } - elseif position(x-1,y+2,'piece') == "knight" and position(x-1,y+2,'color') == color then - thirddata.games.chess.field[0][x-1][y+2] = { color = nil, piece = nil } - elseif position(x+1,y+2,'piece') == "knight" and position(x+1,y+2,'color') == color then - thirddata.games.chess.field[0][x+1][y+2] = { color = nil, piece = nil } - elseif position(x-2,y+1,'piece') == "knight" and position(x-2,y+1,'color') == color then - thirddata.games.chess.field[0][x-2][y+1] = { color = nil, piece = nil } - elseif position(x+2,y+1,'piece') == "knight" and position(x+2,y+1,'color') == color then - thirddata.games.chess.field[0][x+2][y+1] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.process_bishop(piece,color,x,y) - for i=1,7 do - if position(x-i,y-i,'piece') == "bishop" and position(x-i,y-i,'color') == color then - thirddata.games.chess.field[0][x-i][y-i] = { color = nil, piece = nil } - elseif position(x+i,y-i,'piece') == "bishop" and position(x+i,y-i,'color') == color then - thirddata.games.chess.field[0][x+i][y-i] = { color = nil, piece = nil } - elseif position(x-i,y+i,'piece') == "bishop" and position(x-i,y+i,'color') == color then - thirddata.games.chess.field[0][x-i][y+i] = { color = nil, piece = nil } - elseif position(x+i,y+i,'piece') == "bishop" and position(x+i,y+i,'color') == color then - thirddata.games.chess.field[0][x+i][y+i] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.process_rook(piece,color,x,y) - for i=1,7 do - if position(x-i,y,'piece') == piece and position(x-i,y,'color') == color then - thirddata.games.chess.field[0][x-i][y] = { color = nil, piece = nil } - elseif position(x+i,y,'piece') == piece and position(x+i,y,'color') == color then - thirddata.games.chess.field[0][x+i][y] = { color = nil, piece = nil } - elseif position(x,y-i,'piece') == piece and position(x,y-i,'color') == color then - thirddata.games.chess.field[0][x][y-i] = { color = nil, piece = nil } - elseif position(x,y+i,'piece') == piece and position(x,y+i,'color') == color then - thirddata.games.chess.field[0][x][y+i] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.process_rook(piece,color,x,y,file,rank) - local left = true - local right = true - local top = true - local bottom = true - for i=1,7 do - -- file and rank is given - if file ~= nil and rank ~= nil then -- no loop needed - thirddata.games.chess.field[0][tonumber(file)][tonumber(rank)] = { color = nil, piece = nil } - -- file is given - elseif file ~= nil then - if left == true then - if position(x-i,y,'piece') ~= nil and position(x-i,y,'piece') ~= piece then - left = false - elseif position(x-i,y,'piece') == piece and position(x-i,y,'color') == color and (x-i) == tonumber(file) then - thirddata.games.chess.field[0][x-i][y] = { color = nil, piece = nil } - end - end - if right == true then - if position(x+i,y,'piece') ~= nil and position(x+i,y,'piece') ~= piece then - right = false - elseif position(x+i,y,'piece') == piece and position(x+i,y,'color') == color and (x+i) == tonumber(file) then - thirddata.games.chess.field[0][x+i][y] = { color = nil, piece = nil } - end - end - -- rank is given - elseif rank ~= nil then - if top == true then - if position(x,y+i,'piece') ~= nil and position(x,y+i,'color') ~= color and (y+i) == tonumber(rank) then - top = false - elseif position(x,y+i,'piece') == piece and position(x,y+i,'color') == color and (y-i) == tonumber(rank) then - thirddata.games.chess.field[0][x][y+i] = { color = nil, piece = nil } - end - end - if bottom == true then - if position(x,y-i,'piece') ~= nil and position(x,y-i,'color') ~= color then - bottom = false - elseif position(x,y-i,'piece') == piece and position(x,y-i,'color') == color then - thirddata.games.chess.field[0][x][y-i] = { color = nil, piece = nil } - end - end - -- no file or rank is given - else - if left == true then - if position(x-i,y,'piece') ~= nil and position(x-i,y,'piece') ~= piece then - left = false - elseif position(x-i,y,'piece') == piece and position(x-i,y,'color') == color then - thirddata.games.chess.field[0][x-i][y] = { color = nil, piece = nil } - end - end - if right == true then - if position(x+i,y,'piece') ~= nil and position(x+i,y,'piece') ~= piece then - right = false - elseif position(x+i,y,'piece') == piece and position(x+i,y,'color') == color then - thirddata.games.chess.field[0][x+i][y] = { color = nil, piece = nil } - end - end - if top == true then - if position(x,y+i,'piece') ~= nil and position(x,y+i,'color') ~= color then - top = false - elseif position(x,y+i,'piece') == piece and position(x,y+i,'color') == color then - thirddata.games.chess.field[0][x][y+i] = { color = nil, piece = nil } - end - end - if bottom == true then - if position(x,y-i,'piece') ~= nil and position(x,y-i,'color') ~= color then - bottom = false - elseif position(x,y-i,'piece') == piece and position(x,y-i,'color') == color then - thirddata.games.chess.field[0][x][y-i] = { color = nil, piece = nil } - end - end - end - end -end - -function thirddata.games.chess.process_queen(piece,color,x,y) - for i=1,7 do - -- diagonale Richtung - if position(x-i,y-i,'piece') == piece and position(x-i,y-i,'color') == color then - thirddata.games.chess.field[0][x-i][y-i] = { color = nil, piece = nil } - elseif position(x+i,y-i,'piece') == piece and position(x+i,y-i,'color') == color then - thirddata.games.chess.field[0][x+i][y-i] = { color = nil, piece = nil } - elseif position(x-i,y+i,'piece') == piece and position(x-i,y+i,'color') == color then - thirddata.games.chess.field[0][x-i][y+i] = { color = nil, piece = nil } - elseif position(x+i,y+i,'piece') == piece and position(x+i,y+i,'color') == color then - thirddata.games.chess.field[0][x+i][y+i] = { color = nil, piece = nil } - -- horizontale und vertikale Richtung - elseif position(x-i,y,'piece') == piece and position(x-i,y,'color') == color then - thirddata.games.chess.field[0][x-i][y] = { color = nil, piece = nil } - elseif position(x+i,y,'piece') == piece and position(x+i,y,'color') == color then - thirddata.games.chess.field[0][x+i][y] = { color = nil, piece = nil } - elseif position(x,y-i,'piece') == piece and position(x,y-i,'color') == color then - thirddata.games.chess.field[0][x][y-i] = { color = nil, piece = nil } - elseif position(x,y+i,'piece') == piece and position(x,y+i,'color') == color then - thirddata.games.chess.field[0][x][y+i] = { color = nil, piece = nil } - end - end -end - -function thirddata.games.chess.process_king(piece,color,x,y) - if position(x-1,y,'piece') == piece and position(x-1,y,'color') == color then - thirddata.games.chess.field[0][x-1][y] = {color = nil, piece = nil } - elseif position(x+1,y,'piece') == piece and position(x+1,y,'color') == color then - thirddata.games.chess.field[0][x+1][y] = {color = nil, piece = nil } - elseif position(x,y-1,'piece') == piece and position(x,y-1,'color') == color then - thirddata.games.chess.field[0][x][y-1] = {color = nil, piece = nil } - elseif position(x,y+1,'piece') == piece and position(x,y+1,'color') == color then - thirddata.games.chess.field[0][x][y+1] = {color = nil, piece = nil } - elseif position(x-1,y-1,'piece') == piece and position(x-1,y-1,'color') == color then - thirddata.games.chess.field[0][x-1][y-1] = {color = nil, piece = nil } - elseif position(x-1,y+1,'piece') == piece and position(x-1,y+1,'color') == color then - thirddata.games.chess.field[0][x-1][y+1] = {color = nil, piece = nil } - elseif position(x+1,y+1,'piece') == piece and position(x+1,y+1,'color') == color then - thirddata.games.chess.field[0][x+1][y+1] = {color = nil, piece = nil } - elseif position(x+1,y-1,'piece') == piece and position(x+1,y-1,'color') == color then - thirddata.games.chess.field[0][x+1][y-1] = {color = nil, piece = nil } - end -end - -function thirddata.games.chess.processmove(piece,color,x,y,file,rank) - if piece=="pawn" then - thirddata.games.chess.process_pawn(piece,color,x,y,file,rank) - elseif piece=="knight" then - thirddata.games.chess.process_knight(piece,color,x,y,file,rank) - elseif piece=="bishop" then - thirddata.games.chess.process_bishop(piece,color,x,y,file,rank) - elseif piece=="rook" then - thirddata.games.chess.process_rook(piece,color,x,y,file,rank) - elseif piece=="queen" then - thirddata.games.chess.process_queen(piece,color,x,y,file,rank) - elseif piece=="king" then - thirddata.games.chess.process_king(piece,color,x,y,file,rank) - end -end - -function thirddata.games.chess.capturemove(piece,color,x,y,file,rank) - if piece=="pawn" then - thirddata.games.chess.capture_pawn(piece,color,x,y,file,rank) - elseif piece=="knight" then - thirddata.games.chess.process_knight(piece,color,x,y,file,rank) - elseif piece=="bishop" then - thirddata.games.chess.process_bishop(piece,color,x,y,file,rank) - elseif piece=="rook" then - thirddata.games.chess.process_rook(piece,color,x,y,file,rank) - elseif piece=="queen" then - thirddata.games.chess.process_queen(piece,color,x,y,file,rank) - elseif piece=="king" then - thirddata.games.chess.process_king(piece,color,x,y,file,rank) - end -end - -function thirddata.games.chess.board_stones() - tex.sprint("\\vbox\\bgroup\\offinterlineskip") - -- tex.sprint("\\framed[offset=0pt,strut=no]\\bgroup\\vbox\\bgroup\\offinterlineskip") - for row=ny(),1,-1 do - tex.sprint("\\hbox\\bgroup") - for col=1,nx() do - tex.sprint("\\startchessfield") - -- tex.sprint(thirddata.games.chess.board_fieldmask(col,row)) - -- tex.sprint(thirddata.games.chess.board_piecemask(col,row)) - tex.sprint(thirddata.games.chess.board_field(col,row)) - tex.sprint(thirddata.games.chess.board_piece(col,row)) - tex.sprint("\\stopchessfield") - end - tex.sprint("\\egroup") - end - -- tex.sprint("\\egroup\\egroup") - tex.sprint("\\egroup") -end - -function thirddata.games.chess.board_fieldmask(x,y) -end - -function thirddata.games.chess.board_piecemask(x,y) -end - -function thirddata.games.chess.board_field(x,y) - if piece(x,y) ~= nil then - if ifodd(x) and ifodd(y) or ifeven(x) and ifeven(y) then - tex.sprint("{\\chesssymbol{field:" .. color(x,y) .. ":" .. piece(x,y) .. "}}") - end - else - if ifodd(x) and ifodd(y) or ifeven(x) and ifeven(y) then - tex.sprint("{\\chesssymbol{field:black:empty}}") - else - tex.sprint("{\\chesssymbol{field:white:empty}}") - end - end -end - -function thirddata.games.chess.board_piece(x,y) - if piece(x,y) ~= nil then - tex.sprint("{\\chesssymbol{piece:" .. color(x,y) .. ":" .. piece(x,y) .. "}}") - end -end - -function thirddata.games.chess.board_draw(name) - -- tex.sprint("\\startuseMPgraphic{" .. name .. "}{}") - tex.sprint("\\framed[frame=on,offset=none]\\bgroup") - thirddata.games.chess.board_stones() - tex.sprint("\\egroup") - -- tex.sprint("\\stopuseMPgraphic") -end - -end - --- parser - -do - - thirddata = thirddata or { } - thirddata.games = thirddata.games or { } - thirddata.games.pgn = thirddata.games.pgn or { } - - local function processtag(name,text) - tex.sprint(string.format("\\csname pgn!tag\\endcsname{%s}{%s}",name,string.sub(text,2,-2))) - end - - local function processmove(piece,capture,destination,check) - tex.sprint(string.format("\\csname pgn!move\\endcsname{%s}{%s}{%s}{%s}",piece,capture,destination,check)) - end - - local function processnumber(number) - tex.sprint(string.format("\\csname pgn!number\\endcsname{%s}",number)) - end - - local function processcastling(text) - tex.sprint(string.format("\\csname pgn!castling\\endcsname{%s}",text)) - end - - local function processresult(text) - tex.sprint(string.format("\\csname pgn!result\\endcsname{%s}",text)) - end - - local space = lpeg.S(' \r\n')^1 - local lcletter = lpeg.R("az") - local ucletter = lpeg.R("AZ") - local letter = lcletter + ucletter - - local digit = lpeg.R('09')^1 - - local file = lpeg.R('aj')^1 - local rank = lpeg.R('18')^1 - local field = file * rank - local piece = lpeg.S('PNBRQK')^1 - local capture = lpeg.S('x')^1 - - local check = lpeg.S('+#') - - local whitewin = lpeg.P('1-0')^1 - local blackwin = lpeg.P('0-1')^1 - local remis = lpeg.P('1/2-1/2')^1 - local unknown = lpeg.P('*')^1 - - local completecapture = file^0 * rank^0 * capture^1 - - local qsc = lpeg.S('O-O-O')^1 - local ksc = lpeg.S('O-O')^1 - - local result = lpeg.C{ whitewin + blackwin + remis + unknown } / processresult - local castling = lpeg.C{ qsc + ksc } / processcastling - local tag = lpeg.P'[' * lpeg.C(letter^1) * space * lpeg.C{ '"' * ((1 - lpeg.S'""') + lpeg.V(1))^0 * '"' } * lpeg.P']' / processtag - local move = lpeg.C(piece^0) * lpeg.C(completecapture^0) * lpeg.C(field^1) * lpeg.C(check^0) / processmove - local number = lpeg.C(digit^1) * lpeg.P('.') / processnumber - - local parser = (tag + number + move + castling + result + space)^0 - - function thirddata.games.pgn.parse(str) - parser:match(str) - end - -end |