Question

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.

Was it helpful?

Solution

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

OTHER TIPS

    #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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top