⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xqtable.pas

📁 象棋演播室1.6的dephi源码 作者 董世伟
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  if (iPos = 0) then Exit;
  iPos := iPos + Length(sKeyStr);
  iEnd := iPos;
  while(iEnd < Length(s)) do
  begin
    if (s[iEnd] = char($22)) then break;
    Inc(iEnd);
  end;
  sResult := Copy(s, iPos, iEnd - iPos);

  if (sParam = 'Position') then
  begin
    if (Length(sResult) <> (32 * 3 - 1)) then Exit;
    for i:=1 to 32 do
    begin
      b1 := ord(sResult[(i-1)*3 + 1]);
      b2 := ord(sResult[(i-1)*3 + 2]);
      if ((b1 = ord('-'))and (b2 = ord('-'))) then continue;
      if ((b1 < ord('A')) or (b1 > ord('I'))) then Exit;
      if ((b2 < ord('0')) or (b2 > ord('9'))) then Exit;
    end;
  end;

  Result := sResult;
end;

var
  // 在以绝对坐标表示的棋谱中(如12-23),X坐标的初始位置为0还是1
  QipuStrXFrom: Integer = 0;

// 将棋谱记录标准化
procedure dMakeStandardRecStr(var sRecStr: string);
var
  s: string;
begin
  s := sRecStr;

  s := StringReplace(s, ' ' , '', [rfReplaceAll]);

  // Big5-->GB繁体
  s := StringReplace(s,#$AB#$D3, '帅', [rfReplaceAll]);
  s := StringReplace(s,#$B1#$4E, '將', [rfReplaceAll]);
  s := StringReplace(s,#$A5#$4B, '仕', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$68, '士', [rfReplaceAll]);
  s := StringReplace(s,#$AC#$DB, '相', [rfReplaceAll]);
  s := StringReplace(s,#$B6#$48, '象', [rfReplaceAll]);
  s := StringReplace(s,#$DA#$CF, '硨', [rfReplaceAll]);
  s := StringReplace(s,#$A8#$AE, '車', [rfReplaceAll]);
  s := StringReplace(s,#$D8#$58, '傌', [rfReplaceAll]);
  s := StringReplace(s,#$B0#$A8, '馬', [rfReplaceAll]);
  s := StringReplace(s,#$AF#$A5, '砲', [rfReplaceAll]);
  s := StringReplace(s,#$AC#$B6, '炮', [rfReplaceAll]);
  s := StringReplace(s,#$A5#$5D, '包', [rfReplaceAll]);
  s := StringReplace(s,#$A7#$4C, '兵', [rfReplaceAll]);
  s := StringReplace(s,#$A8#$F2, '卒', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$40, '一', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$47, '二', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$54, '三', [rfReplaceAll]);
  s := StringReplace(s,#$A5#$7C, '四', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$AD, '五', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$BB, '六', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$43, '七', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$4B, '八', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$45, '九', [rfReplaceAll]);
  s := StringReplace(s,#$B6#$69, '進', [rfReplaceAll]);
  s := StringReplace(s,#$B0#$68, '退', [rfReplaceAll]);
  s := StringReplace(s,#$A5#$AD, '平', [rfReplaceAll]);
  s := StringReplace(s,#$AB#$65, '前', [rfReplaceAll]);
  s := StringReplace(s,#$A4#$A4, '中', [rfReplaceAll]);
  s := StringReplace(s,#$AB#$E1, '後', [rfReplaceAll]);
  s := StringReplace(s,#$A6#$5A, '后', [rfReplaceAll]);
  
  s := StringReplace(s,#$A2#$B0, '1', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B1, '2', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B2, '3', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B3, '4', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B4, '5', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B5, '6', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B6, '7', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B7, '8', [rfReplaceAll]);
  s := StringReplace(s,#$A2#$B8, '9', [rfReplaceAll]);

  // GB繁体-->GB简体
  s := StringReplace(s, '車'   , '车', [rfReplaceAll]);
  s := StringReplace(s, '砗'   , '车', [rfReplaceAll]);
  s := StringReplace(s, '硨'   , '车', [rfReplaceAll]);
  s := StringReplace(s, '馬'   , '马', [rfReplaceAll]);
  s := StringReplace(s, '码'   , '马', [rfReplaceAll]);
  s := StringReplace(s, '傌'   , '马', [rfReplaceAll]);
  s := StringReplace(s, '相'   , '象', [rfReplaceAll]);
  s := StringReplace(s, '仕'   , '士', [rfReplaceAll]);
  s := StringReplace(s, '帅'   , '将', [rfReplaceAll]);
  s := StringReplace(s, '帥'   , '将', [rfReplaceAll]);
  s := StringReplace(s, '將'   , '将', [rfReplaceAll]);
  s := StringReplace(s, '砲'   , '炮', [rfReplaceAll]);
  s := StringReplace(s, '包'   , '炮', [rfReplaceAll]);
  s := StringReplace(s, '兵'   , '卒', [rfReplaceAll]);
  s := StringReplace(s, '上'   , '进', [rfReplaceAll]);
  s := StringReplace(s, '進'   , '进', [rfReplaceAll]);
  s := StringReplace(s, '下'   , '退', [rfReplaceAll]);
  s := StringReplace(s, '後'   , '后', [rfReplaceAll]);
  s := StringReplace(s, '叁'   , '三', [rfReplaceAll]);

  s := StringReplace(s, '前车' , 'R+', [rfReplaceAll]);
  s := StringReplace(s, '车前' , 'R+', [rfReplaceAll]);
  s := StringReplace(s, '前马' , 'H+', [rfReplaceAll]);
  s := StringReplace(s, '马前' , 'H+', [rfReplaceAll]);
  s := StringReplace(s, '前炮' , 'C+', [rfReplaceAll]);
  s := StringReplace(s, '炮前' , 'C+', [rfReplaceAll]);
  s := StringReplace(s, '前卒' , 'P+', [rfReplaceAll]);
  s := StringReplace(s, '卒前' , 'P+', [rfReplaceAll]);
  s := StringReplace(s, '前士' , 'A+', [rfReplaceAll]);
  s := StringReplace(s, '士前' , 'A+', [rfReplaceAll]);
  s := StringReplace(s, '前象' , 'E+', [rfReplaceAll]);
  s := StringReplace(s, '象前' , 'E+', [rfReplaceAll]);

  s := StringReplace(s, '后车' , 'R-', [rfReplaceAll]);
  s := StringReplace(s, '车后' , 'R-', [rfReplaceAll]);
  s := StringReplace(s, '后马' , 'H-', [rfReplaceAll]);
  s := StringReplace(s, '马后' , 'H-', [rfReplaceAll]);
  s := StringReplace(s, '后炮' , 'C-', [rfReplaceAll]);
  s := StringReplace(s, '炮后' , 'C-', [rfReplaceAll]);
  s := StringReplace(s, '后卒' , 'P-', [rfReplaceAll]);
  s := StringReplace(s, '卒后' , 'P-', [rfReplaceAll]);
  s := StringReplace(s, '后士' , 'A-', [rfReplaceAll]);
  s := StringReplace(s, '士后' , 'A-', [rfReplaceAll]);
  s := StringReplace(s, '后象' , 'E-', [rfReplaceAll]);
  s := StringReplace(s, '象后' , 'E-', [rfReplaceAll]);

  s := StringReplace(s, '车' , 'R', [rfReplaceAll]);
  s := StringReplace(s, '马' , 'H', [rfReplaceAll]);
  s := StringReplace(s, '象' , 'E', [rfReplaceAll]);
  s := StringReplace(s, '士' , 'A', [rfReplaceAll]);
  s := StringReplace(s, '将' , 'K', [rfReplaceAll]);
  s := StringReplace(s, '炮' , 'C', [rfReplaceAll]);
  s := StringReplace(s, '卒',  'P', [rfReplaceAll]);

  s := StringReplace(s, '1' , '1', [rfReplaceAll]);
  s := StringReplace(s, '2' , '2', [rfReplaceAll]);
  s := StringReplace(s, '3' , '3', [rfReplaceAll]);
  s := StringReplace(s, '4' , '4', [rfReplaceAll]);
  s := StringReplace(s, '5' , '5', [rfReplaceAll]);
  s := StringReplace(s, '6' , '6', [rfReplaceAll]);
  s := StringReplace(s, '7' , '7', [rfReplaceAll]);
  s := StringReplace(s, '8' , '8', [rfReplaceAll]);
  s := StringReplace(s, '9' , '9', [rfReplaceAll]);
  s := StringReplace(s, '一' , '1', [rfReplaceAll]);
  s := StringReplace(s, '二' , '2', [rfReplaceAll]);
  s := StringReplace(s, '三' , '3', [rfReplaceAll]);
  s := StringReplace(s, '四' , '4', [rfReplaceAll]);
  s := StringReplace(s, '五' , '5', [rfReplaceAll]);
  s := StringReplace(s, '六' , '6', [rfReplaceAll]);
  s := StringReplace(s, '七' , '7', [rfReplaceAll]);
  s := StringReplace(s, '八' , '8', [rfReplaceAll]);
  s := StringReplace(s, '九' , '9', [rfReplaceAll]);
  s := StringReplace(s, '进' , '+', [rfReplaceAll]);
  s := StringReplace(s, '退' , '-', [rfReplaceAll]);
  s := StringReplace(s, '平' , '.', [rfReplaceAll]);

  sRecStr := s;
end;

// 从字符串中粘贴棋谱记录到棋谱列表
procedure TfrmXQTable.dAddPlayRecordFromString(sLineStr: String);
var
  i, iSkip   : dTInt32;
  iStepNo    : dTInt32;
  XYf, XYt   : dTByte;
  XYft       : dTWord;
  sText, s   : string;
  sRecStr    : String;
  sICSStr    : String;
  sFxqStr    : String; // www.cchess.net 格式
  isQiPuStr  : Boolean;
begin
  iSkip   := 0;
  iStepNo := XQ.PlayStepNo;

  sText := sLineStr;
  dMakeStandardRecStr(sText);
  sText := sText + 'XQStudioQipuStr';

  for i:=1 to (Length(sText)-8) do
  begin
    XYft := $FFFF;

    if (iSkip > 0) then
    begin
      Dec(iSkip);
      Continue;
    end;

    iSkip      := 0;
    sRecStr    := 'C2.5';
    sICSStr    := 'E2-F2';
    isQiPuStr  := False;

    sRecStr[1] := sText[i + 0];
    sICSStr[1] := sText[i + 0];
    sRecStr[2] := sText[i + 1];
    sICSStr[2] := sText[i + 1];
    sRecStr[3] := sText[i + 2];
    sICSStr[3] := sText[i + 2];
    sRecStr[4] := sText[i + 3];
    sICSStr[4] := sText[i + 3];
    sICSStr[5] := sText[i + 4];

    s := UpperCase(sRecStr);
    if ((s[1] in ['K', 'R', 'H', 'N', 'E', 'M', 'A', 'G', 'C', 'P'])and
        (s[2] in ['1'..'9', '+', '-']) and
        (s[3] in ['+', '-', '=', '.']) and
        (s[4] in ['1'..'9'])) then          // 是wxf和axf文件格式
    begin
      case sRecStr[1] of
        'N': sRecStr[1] := 'H';
        'M': sRecStr[1] := 'E';
        'G': sRecStr[1] := 'A';
        'n': sRecStr[1] := 'h';
        'm': sRecStr[1] := 'e';
        'g': sRecStr[1] := 'a';
      end;
      if sRecStr[3] = '=' then sRecStr[3] := '.';
      iSkip   := 3;

      XYft := wGetPlayRecXY(XQ.PlayNode.QiziXY, XQ.WhoPlay, sRecStr);

      isQiPuStr := True;
    end
    else
    begin
      s := UpperCase(sICSStr);
      if ((s[1] in ['A'..'I']) and
          (s[2] in ['0'..'9']) and
          (s[3] = '-') and
          (s[4] in ['A'..'I']) and
          (s[5] in ['0'..'9'])) then          // 是ICCS文件格式
      begin
        iSkip     := 4;
        s         := UpperCase(sICSStr);
        XYft      := (Ord(s[1])-Ord('A'))*10+(Ord(s[2])-Ord('0'));
        XYft      := XYft shl 8;
        XYft      := XYft + (Ord(s[4])-Ord('A'))*10+(Ord(s[5])-Ord('0'));
        isQiPuStr := True;
      end
      else
      begin
        if ((s[1] in ['0'..'9']) and
            (s[2] in ['0'..'9']) and
            (s[3] = '-') and
            (s[4] in ['0'..'9']) and
            (s[5] in ['0'..'9'])) then          // 是CCK Java文件格式
        begin
          s[1] := chr(ord('A') + ord(s[1]) - ord('0') - QipuStrXFrom);
          s[2] := chr(ord('0') + (9 - (ord(s[2]) - ord('0'))));
          s[4] := chr(ord('A') + ord(s[4]) - ord('0') - QipuStrXFrom);
          s[5] := chr(ord('0') + (9 - (ord(s[5]) - ord('0'))));
          iSkip     := 4;
          XYft      := (Ord(s[1])-Ord('A'))*10+(Ord(s[2])-Ord('0'));
          XYft      := XYft shl 8;
          XYft      := XYft + (Ord(s[4])-Ord('A'))*10+(Ord(s[5])-Ord('0'));
          isQiPuStr := True;
        end
        else
        begin
          sFxqStr := Copy(sText, i, 8);
          s       := sFxqStr;
          if ((s[1] in ['1'..'2']) and
              (s[2] in ['1'..'7']) and
              (s[3] in ['0'..'8']) and
              (s[4] in ['0'..'9']) and
              (s[5] in ['0'..'8']) and
              (s[6] in ['0'..'9']) and
              (s[7] in ['0'..'2']) and
              (s[8] in ['0'..'7'])) then          // 是Fxq Java文件格式
          begin
            iSkip     := 7;
            XYft      := (Ord(s[3])-Ord('0'))*10+(9-(Ord(s[4])-Ord('0')));
            XYft      := XYft shl 8;
            XYft      := XYft + (Ord(s[5])-Ord('0'))*10+(9-(Ord(s[6])-Ord('0')));
            isQiPuStr := True;
          end;
        end;
      end;
    end;

    if isQiPuStr then
    begin
      XYf  := XYft shr 8;
      XYt  := XYft and $00FF;

      if Not ((XYf in [00..89]) and (XYt in [00..89])) then Break;

      XQ.dStartMoveFromXY(XYf);
      XQ.dStopMoveAtXY(XYt);

      if (XQ.PlayStepNo<>iStepNo) then
      begin
        isXQFileChange := True;
        XQ.dDispQiziAtRecNo(XQ.PlayStepNo);
        iStepNo := XQ.PlayStepNo;
      end;
    end;
  end; // end of for
end;

// 检查文本是否是由XQStudio自动生成的
function isTextIsXQFText(sText: String): Boolean;
begin

  if Pos('棋谱由XQStudio软件自动生成', sText) > 0 then
  begin
    Result := True;
    Exit;
  end;

  Result := (Pos('红方:', sText) > 0) and
            (Pos('黑方:', sText) > 0) and
            (Pos('结果:', sText) > 0) and
            (Pos('评论:', sText) > 0) and
            (Pos('----------------', sText) > 0);
end;

// 检查文本是否是由XQStudio自动生成的JavaXQ Html
function isTextIsXQVHtml(sText: String): Boolean;
begin
  Result := False;
  if Pos('<!GENERATOR name="XQStudio"', sText) > 0 then
  begin
    Result := True;
  end;
  if Pos('<!PARAM name="Position"', sText) > 0 then
  begin
    Result := True;
  end;
end;

// 检查是否是棋谱行
function isQiPuLine(sLine: string): Boolean;
var
  s: string;
begin
   Result := False;
   s := sLine;
   s := TrimLeft(s);
   if Length(s) < 1 then Exit;
   if not (pos('.', s) in [1..4]) then Exit;
   if s[1] in ['0'..'9'] then Result := True;
end;

// 粘贴棋图
procedure TfrmXQTable.ppmPasteQipuClick(Sender: TObject);
var
  s            : String;
  iXY          : Integer;
  i, iStepNo   : Integer;
  isXQFText    : Boolean;
  isXQVHtml    : Boolean;
  isCheckRemark: Boolean;
begin
  Screen.Cursor := crHourGlass;

  memQiTuText.ReadOnly := False;
  if Sender <> nil then
  begin
    memQiTuText.Clear;
    memQiTuText.PasteFromClipboard;
  end;

  // 查找标题、赛事等棋局的说明信息
  if (sTitle = '') then
    sTitle     := sGetStrAfterKeyWord(memQiTuText.Lines, '标题:');
  if (sMatchName = '') then
    sMatchName := sGetStrAfterKeyWord(memQiTuText.Lines, '赛事:');
  if (sMatchTime = '') then
    sMatchTime := sGetStrAfterKeyWord(memQiTuText.Lines, '日期:');
  if (sMatchTime = '') then
    sMatchTime := sGetStrAfterKeyWord(memQiTuText.Lines, '时间:');
  if (sMatchAddr = '') then
    sMatchAddr := sGetStrAfterKeyWord(memQiTuText.Lines, '地点:');
  if (sRedPlayer = '') then
    sRedPlayer := sGetStrAfterKeyWord(memQiTuText.Lines, '红方:');
  if (sBlkPlayer = '') then
    sBlkPlayer := sGetStrAfterKeyWord(memQiTuText.Lines, '黑方:');
  if (sRMKWriter = '') then
    sRMKWriter := sGetStrAfterKeyWord(memQiTuText.Lines, '评论:');
  if (sAuthor = '') then
    sAuthor    := sGetStrAfterKeyWord(memQiTuText.Lines, '作者:');
  if (iResult = 0) then
  begin
    s          := sGetStrAfterKeyWord(memQiTuText.Lines, '结果:');
    if (s = '红方胜') then iResult := 1;
    if (s = '黑方胜') then iResult := 2;
    if (s = '和棋')   then iResult := 3;
  end;

  //******2007-05-22 加入对象棋大师网导出棋谱的支持 ****************************
  // 查找标题、赛事等棋局的说明信息
  if (sTitle = '') then
    sTitle     := sGetStrAfterKeyWord(memQiTuText.Lines, '棋 局 名:');
  if (sMatchName = '') then
    sMatchName := sGetStrAfterKeyWord(memQiTuText.Lines, '比赛名称:');
  if (sMatchTime = '') then
    sMatchTime := sGetStrAfterKeyWord(memQiTuText.Lines, '比赛时间:');
  if (sMatchAddr = '') then
    sMatchAddr := sGetStrAfterKeyWord(memQiTuText.Lines, '比赛地点:');
  if (sRedPlayer = '') then
    sRedPlayer := sGetStrAfterKeyWord(memQiTuText.Lines, '红    方:');
  if (sBlkPlayer = '') then
    sBlkPlayer := sGetStrAfterKeyWord(memQiTuText.Lines, '黑    方:');
  if (iResult = 0) then
  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -