-4

I have this c# class and i want to Implement this on 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();
            }
        }
    }

So Far I got this far

    #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] Unexpected keyword 'member' in expression

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

[error here] Incomplete structured construct at or before this point in definition. Expected incomplete structured construct at or before this point or other token.

4

2 回答 2

4

You need to declare a backing store for the variables, just like you would in C#. Something like

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
于 2013-10-01T04:37:22.427 回答
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
于 2013-10-01T05:09:08.490 回答