2012-01-04 12 views
5

हम अपने आप को लागू करने से पहले, क्या जावा कोड का एक मौजूदा ओपन सोर्स टुकड़ा है जो शतरंज FEN स्ट्रिंग लेता है और इसे शतरंज बोर्ड के HTML प्रतिनिधित्व में परिवर्तित करता है?एफएन (शतरंज नोटेशन) एचटीएमएल जनरेटर के लिए? ओपन सोर्स जावा

एक दलदल कोड इस तरह दिखता है: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

कुछ

उत्पादन होगा <table><tr><td>♘</td><td>♛</td><td>... तरह

एक प्रतीक के आधार पर समाधान, या यहाँ तक कि एक समाधान है कि HTML के बजाय एक बड़ी छवि पैदा करता है, भी स्वीकार्य हो सकता है । यह एक एंड्रॉइड ऐप में एकीकरण के लिए है।

(Here is an implementation in Python)

+1

छवियां क्यों? यूनिकोड का शतरंज प्रतीक हिस्सा नहीं हैं? –

+0

@ केरेकस्क: वास्तव में! यह भी ठीक होगा। मेरा प्रश्न अपडेट कर रहा है। –

+0

एचएम, एक अच्छा लाटेक्स पैकेज ("स्कैक") प्रतीत होता है, और हमेशा LaTeX2HTML है, लेकिन यह अपमानजनक लगता है। एक सीधा-से-एचटीएमएल समाधान अच्छा होगा। –

उत्तर

5

मैं इस जगह से कुछ उपयोगी CSS3 पाया:

<html> 
<head> 
    <style type="text/css"> 
     .chess_board { border:1px solid #333; } 
     .chess_board td { 
      background:#fff; background:-moz-linear-gradient(top, #fff, #eee); 
      background:-webkit-gradient(linear,0 0, 0 100%, from(#fff), to(#eee)); 
      box-shadow:inset 0 0 0 1px #fff; 
      -moz-box-shadow:inset 0 0 0 1px #fff; 
      -webkit-box-shadow:inset 0 0 0 1px #fff; 
      height:40px; text-align:center; vertical-align:middle; width:40px; font-size:30px;} 
     .chess_board tr:nth-child(odd) td:nth-child(even), 
     .chess_board tr:nth-child(even) td:nth-child(odd) { 
      background:#ccc; background:-moz-linear-gradient(top, #ccc, #eee); 
      background:-webkit-gradient(linear,0 0, 0 100%, from(#ccc), to(#eee)); 
      box-shadow:inset 0 0 10px rgba(0,0,0,.4); 
      -moz-box-shadow:inset 0 0 10px rgba(0,0,0,.4); 
      -webkit-box-shadow:inset 0 0 10px rgba(0,0,0,.4); } 
    </style> 
    <script type="text/javascript"> 
     function renderFen(fentxt) { 
      fentxt = fentxt.replace(/ .*/g, ''); 
      fentxt = fentxt.replace(/r/g, 'x'); // Convert black rooks to 'x' to avoid mixup with <tr></tr> tags 
      fentxt = fentxt.replace(/\//g, '</tr><tr>'); 
      fentxt = fentxt.replace(/1/g, '<td></td>'); 
      fentxt = fentxt.replace(/2/g, '<td></td><td></td>'); 
      fentxt = fentxt.replace(/3/g, '<td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/4/g, '<td></td><td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/5/g, '<td></td><td></td><td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/6/g, '<td></td><td></td><td></td><td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/7/g, '<td></td><td></td><td></td><td></td><td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/8/g, '<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>'); 
      fentxt = fentxt.replace(/K/g, '<td>&#9812;</td>'); 
      fentxt = fentxt.replace(/Q/g, '<td>&#9813;</td>'); 
      fentxt = fentxt.replace(/R/g, '<td>&#9814;</td>'); 
      fentxt = fentxt.replace(/B/g, '<td>&#9815;</td>'); 
      fentxt = fentxt.replace(/N/g, '<td>&#9816;</td>'); 
      fentxt = fentxt.replace(/P/g, '<td>&#9817;</td>'); 
      fentxt = fentxt.replace(/k/g, '<td>&#9818;</td>'); 
      fentxt = fentxt.replace(/q/g, '<td>&#9819;</td>'); 
      fentxt = fentxt.replace(/x/g, '<td>&#9820;</td>'); 
      fentxt = fentxt.replace(/b/g, '<td>&#9821;</td>'); 
      fentxt = fentxt.replace(/n/g, '<td>&#9822;</td>'); 
      fentxt = fentxt.replace(/p/g, '<td>&#9823;</td>'); 
      return '<table class="chess_board" cellspacing="0" cellpadding="0"><tr>' + fentxt + '</tr></table>'; 
     } 
    </script> 
</head> 
<body> 
    <script type="text/javascript"> 
     document.write(renderFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')); 
    </script> 
</body> 

1

अलेक्जेंडर Maryanovsky जिन के site से हवाला देते हुए: http://designindevelopment.com/css/css3-chess-board/
तो मैं निम्नलिखित के साथ आया था साइट:

जिन

जिन के बारे में एक खुला स्रोत, पार मंच, शतरंज सर्वर के लिए चित्रमय ग्राहक, जावा में लिखा है। जिन या तो आपके ब्राउज़र (शतरंज सर्वर की वेबसाइट पर उपलब्ध) से सीधे से सीधे एक स्टैंडअलोन एप्लिकेशन (इस वेबसाइट पर उपलब्ध) या एक एप्लेट के रूप में चला सकता है।

उनकी परियोजना ओपन सोर्स है और Sourceforge पर उपलब्ध है।

Position.java कक्षा प्राप्त करें और आपको जावा कोड हैंडलिंग FEN का कुछ टुकड़ा मिलेगा।

+0

+1 मैंने पहले से ही एक जवाब स्वीकार कर लिया है, लेकिन तथ्य यह है कि जिन जावा में जावा है, यह मेरे लिखित प्रश्न का एक करीबी जवाब देता है (भले ही मेरे विशेष उपयोग मामले में जावास्क्रिप्ट वास्तव में ठीक है) –

संबंधित मुद्दे