Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

FEN Zeichenkette zu HTML Dokument konvertieren (DLL Beispiel)

Uploader:MitgliedRoland Chastain
Datum/Zeit:12.08.2014 20:45:57

'-------------------------------------------------------------------------------
' dll.bi

declare function HtmlDoc alias "HtmlDoc" ( _
  byval aPlacement as string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", _
  byval aCharSet as string = "!""#$%/() +pPoOnNmMbBvVrRtTqQwWkKlL", _
  byval aTitle as string = "", _
  byval aFont as string = "chess alfonso-x", _
  byval aSize as string = "40px", _
  byval aColor as string = "black", _
  byval aBkColor as string = "white" _
) as string

'-------------------------------------------------------------------------------
' dll.bas
' Kommandozeile : fbc -dll dll.bas

' Converts the first field of an FEN string to an HTML document.
' The default font is Chess Alfonso-X by Armando H. Marroquin.
' If you want to use another chess font by the same author, you just have to
' change the font name, otherwise you must also change the character set,
' because each author uses a different one.
' N.B. The FEN string is assumed to be valid.

' Chess font Alfonso-X
' http://www.enpassant.dk/chess/fonteng.htm

' Forsyth-Edwards notation
' http://kirill-kryukov.com/chess/doc/fen.html

#include once "dll.bi"

#define EOL chr(13, 10)

function HtmlDoc( _
  byval aPlacement as string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", _
  byval aCharSet as string = "!""#$%/() +pPoOnNmMbBvVrRtTqQwWkKlL", _
  byval aTitle as string = "", _
  byval aFont as string = "chess alfonso-x", _
  byval aSize as string = "40px", _
  byval aColor as string = "black", _
  byval aBkColor as string = "white" _
) as string export

  dim as string head, body, foot
  dim as integer i, j, x, y

  head = _
  "<!DOCTYPE html>" & EOL & _
  "<html>" & EOL & _
  "<head>" & EOL & _
  "<title>" & aTitle & "</title>" & EOL & _
  "<style type=""text/css"">" & EOL & _
  "p {" & EOL & _
  "font-family: " & aFont & ";" & EOL & _
  "font-size: " & aSize & ";" & EOL & _
  "color: " & aColor & ";" & EOL & _
  "background-color: " & aBkColor & ";" & EOL & _
  "}" & EOL & _
  "</style>" & EOL & _
  "</head>" & EOL & _
  "<body>" & EOL

  body = ""
  i = 0
  x = 1
  y = 8
  do while (len(body) < 64) and (i <= len(aPlacement) - 1)
    if aPlacement[i] = asc("/") then
      x = 1
      y -= 1
      i += 1
    else
      if (aPlacement[i] >= asc("1")) and (aPlacement[i] <= asc("8")) then
        do while aPlacement[i] > asc("0")
          body &= iif((x + y) mod 2 = 1, chr(aCharSet[8]), chr(aCharSet[9]))
          x += 1
          aPlacement[i] -= 1
        loop
        i += 1
      else
        if instr("bknpqrBKNPQR", chr(aPlacement[i])) > 0 then
          select case lcase(chr(aPlacement[i]))
            case "p"
              j = 10
            case "n"
              j = 14
            case "b"
              j = 18
            case "r"
              j = 22
            case "q"
              j = 26
            case "k"
              j = 30
          end select
          ' dark square
          if (x + y) mod 2 = 0 then j += 1
          ' black piece
          if chr(aPlacement[i]) = lcase(chr(aPlacement[i])) then j += 2
          body &= chr(aCharSet[j])
          x += 1
          i += 1
        else
          exit do
        end if
      end if
    end if
  loop

  body = _
  "<p>" & EOL & _
  chr(aCharSet[0]) & string(8, aCharSet[1])  & chr(aCharSet[2]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 0 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 1 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 2 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 3 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 4 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 5 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 6 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[3]) & mid(body, 1 + 7 * 8, 8) & chr(aCharSet[4]) & "<br>" & EOL & _
  chr(aCharSet[5]) & string(8, aCharSet[6])  & chr(aCharSet[7]) & "<br>" & EOL & _
  "</p>" & EOL

  foot = _
  "</body>" & EOL & _
  "</html>"

  function = head & body & foot

end function

'-------------------------------------------------------------------------------
' verwendung1.bas

' DLL Verwendungsbeispiel 1

#include "dll.bi"
#inclib "dll"

open "position.htm" for output as #1
print #1, HtmlDoc()
close #1

'-------------------------------------------------------------------------------
' verwendung2.bas

' DLL Verwendungsbeispiel 2

dim library as any ptr

dim HtmlDoc as function( _
  byval aPlacement as string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", _
  byval aCharSet as string = "!""#$%/() +pPoOnNmMbBvVrRtTqQwWkKlL", _
  byval aTitle as string = "", _
  byval aFont as string = "chess alfonso-x", _
  byval aSize as string = "40px", _
  byval aColor as string = "black", _
  byval aBkColor as string = "white" _
) as string

library = dylibload("dll")
HtmlDoc = dylibsymbol(library, "HtmlDoc")

open "position.htm" for output as #1
print #1, HtmlDoc()
close #1

dylibfree library

'-------------------------------------------------------------------------------
' verwendung3.bas

' DLL Verwendungsbeispiel 3

extern "C" LIB "dll"
  declare function HtmlDoc stdcall alias "HtmlDoc" ( _
    byval aPlacement as string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR", _
    byval aCharSet as string = "!""#$%/() +pPoOnNmMbBvVrRtTqQwWkKlL", _
    byval aTitle as string = "", _
    byval aFont as string = "chess alfonso-x", _
    byval aSize as string = "40px", _
    byval aColor as string = "black", _
    byval aBkColor as string = "white" _
  ) as string
end extern

open "position.htm" for output as #1
print #1, HtmlDoc()
close #1