C#给F#好玩

时间:2013-10-01 04:33:46

标签: c# class f# implementation

我有这个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)  =

[error here]表达式中的意外关键字“成员”

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

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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