2013-10-01 51 views
-4

我有这个C#类和我想要实现这个在F#C#向F#的乐趣

using System; 
    using AIInterface; 
    using Boards; 

    namespace TTTAiCSharpAlphaBate 
    { 
     public class AI : IAI 
     { 
      private int symbol; 
      Board cBoard; 
      int aiLevel = 1; 
      string IAI.GetAIName() 
      { 
       return "C#AlphaBetaAi"; 
      } 

      string IAI.GetAIVersion() 
      { 
       return "1.0.0"; 
      } 

      void IAI.SetAI(Boards.Board board, int level, int symbol) 
      { 
       cBoard = board; 
       this.symbol = symbol; 
       aiLevel = level; 

      } 

      int[] IAI.GetLevel() 
      { 
       return new int[1] { 3 }; 
      } 

      int IAI.AIMove() 
      { 
       throw new NotImplementedException(); 
      } 
     } 
    } 

到目前为止,我能走到今天

#if Board 
    #r @"c:\..\bin\Debug\Boards.dll" 
    #r @"c:\..\bin\Debug\AIInterface.dll" 
    #endif 
    module TTTAiFSharpAlphaBeta 
    open AIInterface 
    open Boards 
    type AI()= 
      interface IAI with 
       member this.SetAI (board: Board ,level:int, symbol:int) = 

[错误位置]意外的关键字“成员“在表达

    member this.cboard = board 
        member this.level = level 
        member this.symbol = symbol 

[错误这里] 定义中的此点或之前的不完整结构化构造 。在此点或其他标记之前或之前构建的预期不完整结构 。

+1

东西在猜测,它显示了很少的研究工作。 –

回答

4

您需要为变量声明一个后备存储,就像在C#中一样。像

type AI()= 
     let mutable cboard = (*Something*) 
     let mutable level = 0 
     let mutable symbol = 0 
     interface IAI with 
      member this.SetAI (_board ,_level, _symbol) = 
       cboard <- _board 
       level <- _level 
       symbol <- _symbol 
0
#if Board 
    #r @"L:\..\bin\Debug\Boards.dll" 
    #r @"L:\..\bin\Debug\AIInterface.dll" 
    #endif 
    module TTTAiFSharpAlphaBeta 
    open AIInterface 
    open Boards 
    type AI()= 
      let mutable cboard =new Board() 
      let mutable level = 0 
      let mutable symbol = 0 
      interface IAI with 
       member this.SetAI (board: Board ,_level, _symbol) = 
        cboard <- board 
        level <- _level 
        symbol <- _symbol 
       member this.GetAIName()="F#DumbAssAI" 
       member this.GetAIVersion()="0.0.1" 
       member this.GetLevel()= [| 10 |]; 
       member this.AIMove()=1