Ejemplo n.º 1
0
        public ILink createLink(string PrecursorID, string FollowerID, eLnkType type, double delay)
        {
            identity prec = _project.getTaskFactory().getTask(PrecursorID).getIDobject();
            identity foll = _project.getTaskFactory().getTask(FollowerID).getIDobject();

            return(createLink(prec, foll, type, 0));
        }
Ejemplo n.º 2
0
        public override Move getMove()
        {
            //Create the resulting move
            Move result = new Move();

            //Get first player identity and board
            identity first = Program.getFirstPlayer();
            Board    board = Program.getBoard();

            //Decide if this is whites turn or not
            bool isWhitesTurn = (first == this.getIdentity());


            //Get the move from the AI DLL
            AIMove nextMove = AIGetMove(board.blackCount, board.whiteCount, board.blackRows, board.whiteRows, isWhitesTurn);

            //Convert the AIMove to a Move class
            result.Begin.X = nextMove.row;
            result.Begin.Y = nextMove.col;
            if (isWhitesTurn)
            {
                result.End.X = nextMove.row + 1;
            }
            else
            {
                result.End.X = nextMove.row - 1;
            }
            result.End.Y = nextMove.col + nextMove.target - 1;

            //Return the result
            return(result);
        }
Ejemplo n.º 3
0
        //Begin the game
        private static void beginGame(identity firstID, ref Player xPlayer, ref Player oPlayer, ref GameBoard Game,
                                      ref Move move)
        {
            Player currentPlayer;

            if (firstID == identity.X)
            {
                currentPlayer = xPlayer;
            }
            else
            {
                currentPlayer = oPlayer;
            }

            while (!Game.gameOver())
            {
                // Console.Write("AI Favors at " + global::AI.AICore.evaluate1(true, game.getBoard()) + "\n");
                //Console.Write(currentPlayer.getIdentity() + " to move...\n");
                move = currentPlayer.getMove();

                Game.movePiece(currentPlayer.getIdentity(), move);
                Console.Clear();
                Game.printGameBoard();

                if (currentPlayer.getIdentity() == identity.X)
                {
                    currentPlayer = oPlayer;
                }
                else
                {
                    currentPlayer = xPlayer;
                }
            }
        }
Ejemplo n.º 4
0
        public int getWinNum(identity id)
        {
            string sql = @"SELECT winNum
                           FROM RECORD
                           WHERE identity = ?";

            using (var statement = connRecord.Prepare(sql))
            {
                if (id == identity.black)
                {
                    statement.Bind(1, "黑方");
                }
                else if (id == identity.white)
                {
                    statement.Bind(1, "白方");
                }
                else if (id == identity.man)
                {
                    statement.Bind(1, "人");
                }
                else if (id == identity.computer)
                {
                    statement.Bind(1, "电脑");
                }
                statement.Step();
                if (statement[0] != null)
                {
                    return(int.Parse(statement[0].ToString()));
                }
                else
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 5
0
        public void addWinNum(identity id)
        {
            string sql = @"UPDATE RECORD
                           SET winNum = winNum + 1
                           WHERE identity = ?";

            using (var statement = connRecord.Prepare(sql))
            {
                if (id == identity.black)
                {
                    statement.Bind(1, "黑方");
                }
                else if (id == identity.white)
                {
                    statement.Bind(1, "白方");
                }
                else if (id == identity.man)
                {
                    statement.Bind(1, "人");
                }
                else if (id == identity.computer)
                {
                    statement.Bind(1, "电脑");
                }
                statement.Step();
            }
        }
Ejemplo n.º 6
0
    public static animationTransformData average(identity nIdentity, animationTransformData pose_0, animationTransformData pose_1, float parameter0, float parameter1, bool usingQuaternion)
    {
        animationTransformData newPose_0 = scale(new identity(), pose_0, parameter0, usingQuaternion);
        animationTransformData newPose_1 = scale(new identity(), pose_1, parameter1, usingQuaternion);

        return(add(newPose_0, newPose_1, usingQuaternion));
    }
Ejemplo n.º 7
0
        public static Move getAMove(bool isWhitesTurn)
        {
            //Create the resulting move
            Move result = new Move();

            //Get first player identity and board
            identity first = Program.getFirstPlayer();
            Board    board = Program.getBoard();

            //Convert to AISpace
            ulong[,] AISQUARES = { {                 1,                  2,                  4,                  8,               16,               32,                64,               128 },
                                   {               256,                512,               1024,               2048,             4096,             8192,             16384,             32768 },
                                   {             65536,             131072,             262144,             524288,          1048576,          2097152,           4194304,           8388608 },
                                   {          16777216,           33554432,           67108864,          134217728,        268435456,        536870912,        1073741824,        2147483648 },
                                   {        4294967296,         8589934592,        17179869184,        34359738368,      68719476736,     137438953472,      274877906944,      549755813888 },
                                   {     1099511627776,      2199023255552,      4398046511104,      8796093022208,   17592186044416,   35184372088832,    70368744177664,   140737488355328 },
                                   {   281474976710656,    562949953421312,   1125899906842624,   2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968 },
                                   { 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488,
                                     1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808 } };


            ulong black = 0;
            ulong white = 0;

            for (uint i = 0; i < 8; i++)
            {
                for (uint j = 0; j < 8; j++)
                {
                    if (board.blackRows[i] % board.COLUMNS[j] == 0)
                    {
                        black += AISQUARES[i, j];
                    }
                    if (board.whiteRows[i] % board.COLUMNS[j] == 0)
                    {
                        white += AISQUARES[i, j];
                    }
                }
            }


            //Get the move from the AI DLL
            AIMove nextMove = AIGetMove(board.blackCount, board.whiteCount, black, white, isWhitesTurn, 0);

            //Convert the AIMove to a Move class
            result.Begin.X = checked ((int)nextMove.row);
            result.Begin.Y = checked ((int)nextMove.col);
            if (isWhitesTurn)
            {
                result.End.X = checked ((int)nextMove.row + 1);
            }
            else
            {
                result.End.X = checked ((int)nextMove.row - 1);
            }
            result.End.Y = checked ((int)(nextMove.col + nextMove.target - 1));

            //Return the result
            return(result);
        }
Ejemplo n.º 8
0
        //Initializing a New Gameboard
        public void newGameBoard(identity firstPlayer)
        {
            board            = new Board();
            this.firstPlayer = firstPlayer;
            Debug.Log(firstPlayer);

            //printGameBoard();
        }
Ejemplo n.º 9
0
            internal static bool RemoteTestCase()
            {
                typeof(fastCSharp.config.pub).GetProperty("IsDebug", BindingFlags.Instance | BindingFlags.Public).SetValue(fastCSharp.config.pub.Default, true, null);
                using (fastCSharp.memoryDatabase.physicalServer.tcpServer server = new fastCSharp.memoryDatabase.physicalServer.tcpServer(tcpServer))
                {
                    if (server.Start())
                    {
                        using (memoryDatabaseModelTable <identity> .remote table = new memoryDatabaseModelTable <identity> .remote(new fastCSharp.memoryDatabase.physicalServer.tcpClient(tcpServer), cache = new identityArray <identity>()))
                        {
                            updateMember = table.CreateMemberMap().Append(value => value.Int);
                            cache.WaitLoad();
                            if (cache.Count == 0)
                            {
                                identity int1 = table.Insert(new identity {
                                    Int = 1, String = "A大A"
                                }, false);
                                identity intOld2 = new identity {
                                    Int = 2
                                };
                                identity int2 = table.Insert(intOld2);
                                identity int4 = table.Insert(new identity {
                                    Int = 4
                                });
                                if (int1 == null)
                                {
                                    return(false);
                                }
                                if (int2 == null)
                                {
                                    return(false);
                                }
                                if (int4 == null)
                                {
                                    return(false);
                                }

                                intOld2.Int = 3;
                                identity int3 = table.Update(intOld2, updateMember);
                                if (int3 == null)
                                {
                                    return(false);
                                }
                                identity delete = table.Delete(int4.Id);
                                if (delete == null)
                                {
                                    return(false);
                                }

                                return(check(table, false));
                            }
                            return(check(table, true));
                        }
                    }
                }
                return(false);
            }
Ejemplo n.º 10
0
        public linkFactory(IProject project, Action destroyMethod)
        {
            _ID      = new identity(eEntity.factory);
            dctLinks = new Dictionary <string, link>();

            _project = project;
            project.event_projectDelete += handler_projectDelete;

            destroyMethod = deleteThis;
        }
Ejemplo n.º 11
0
 public static Square fromOppositeIdentity(identity id)
 {
     if (id == identity.O)
     {
         return(Square.X);
     }
     else
     {
         return(Square.O);
     }
 }
Ejemplo n.º 12
0
        public bool checkMove(identity currentPlayer, Move move)
        {
            bool isFirstsTurn = false;

            if (firstPlayer == currentPlayer)
            {
                isFirstsTurn = true;
            }

            //Try the move check on the Low Abstraction Board
            return(board.makeMove(isFirstsTurn, move.Begin.X, move.Begin.Y, move.End.X, move.End.Y, true));
        }
Ejemplo n.º 13
0
        public ILink createLink(identity PrecursorID, identity FollowerID, eLnkType type, double delay)
        {
            link newLink = new link(_project,
                                    _project.getTaskFactory().getTask(PrecursorID),
                                    _project.getTaskFactory().getTask(FollowerID),
                                    type, delay);

            newLink.event_linkDeleted += handler_linkDelete;
            addElement(newLink);

            return(newLink);
        }
Ejemplo n.º 14
0
        public link(IProject Project, ITask Precursor, ITask Follower, eLnkType type, double delay = 0)
        {
            _ID = new identity(eEntity.link);

            _project = Project;
            _project.getLinkFactory().event_linkFactoryDelete += handler_factoryDelete;

            _precursor = Precursor;
            _follower  = Follower;

            lnkLimit  = new limit(link.lnk2lim(type), __hlp.initDate);
            tpManager = new typeManager(this, type, delay);
        }
Ejemplo n.º 15
0
        public bool movePiece(identity currentPlayer, Move move)
        {
            //If the current player is the first player, then white is moving
            bool isFirstsTurn = false;

            if (firstPlayer == currentPlayer)
            {
                isFirstsTurn = true;
            }

            //Execute the move on the Low Abstraction Board
            return(board.makeMove(isFirstsTurn, move.Begin.X, move.Begin.Y, move.End.X, move.End.Y, false));
        }
Ejemplo n.º 16
0
        private void buttonNext_Click(object sender, EventArgs e)
        {
            identity user = IdentityVerify();

            if (user == identity.AdminProxy)
            {
                this.frmMain.SceneTransit(Roster.A_P_EntryBoxCode);
            }
            else if (user == identity.Administrator)
            {
                this.frmMain.SceneTransit(Roster.A_ControlPanel);
            }
        }
Ejemplo n.º 17
0
        public bool checkMove(identity currentPlayer, Move move)
        {
            //Flip the move if needed
            Move boardRelativeMove = flipMoveIfNeeded(move);

            bool isFirstsTurn = false;

            if (firstPlayer == currentPlayer)
            {
                isFirstsTurn = true;
            }

            //Try the move check on the Low Abstraction Board
            return(board.makeMove(isFirstsTurn, boardRelativeMove.Begin.row, boardRelativeMove.Begin.col, boardRelativeMove.End.row, boardRelativeMove.End.col, true));
        }
Ejemplo n.º 18
0
            internal static bool TestCase()
            {
                using (memoryDatabaseModelTable <identity> table = new memoryDatabaseModelTable <identity>(cache = new identityArray <identity>(), memoryDatabaseTable.serializeType.Index, "localIdentity"))
                {
                    updateMember = table.CreateMemberMap().Append(value => value.Int);
                    cache.WaitLoad();
                    if (cache.Count == 0)
                    {
                        identity int1 = table.Insert(new identity {
                            Int = 1, String = "A大A"
                        }, false);
                        identity intOld2 = new identity {
                            Int = 2
                        };
                        identity int2 = table.Insert(intOld2);
                        identity int4 = table.Insert(new identity {
                            Int = 4
                        });
                        if (int1 == null)
                        {
                            return(false);
                        }
                        if (int2 == null)
                        {
                            return(false);
                        }
                        if (int4 == null)
                        {
                            return(false);
                        }

                        intOld2.Int = 3;
                        identity int3 = table.Update(intOld2, updateMember);
                        if (int3 == null)
                        {
                            return(false);
                        }
                        identity delete = table.Delete(int4.Id);
                        if (delete == null)
                        {
                            return(false);
                        }

                        return(check(table, false));
                    }
                    return(check(table, true));
                }
            }
Ejemplo n.º 19
0
        public string gameBoardString()
        {
            String result = "";

            //Set the second player attribute to have
            //the opposite identity of the first player
            identity secondPlayer = identity.O;

            if (firstPlayer == identity.O)
            {
                secondPlayer = identity.X;
            }

            //Display each row (loops backwards for right way up)
            for (int i = ROW - 1; i >= 0; i--)
            {
                //Write the row number
                result += " " + (i + 1);
                result += " ";

                //Display each piece
                for (int j = 0; j < COL; j++)
                {
                    char peice = board.getPieceAt(i, j);
                    if (peice == 'W')
                    {
                        result += firstPlayer;
                    }
                    else if (peice == 'B')
                    {
                        result += secondPlayer;
                    }
                    else
                    {
                        result += " ";
                    }


                    result += " "; // Temporary to see what is going on
                }
                result += "\n";    // Temporary to see what is going on
            }

            //Display the column ids
            result += "  A B C D E F G H\n";

            return(result);
        }
Ejemplo n.º 20
0
        public identity FormsAuthTicketToidentity(FormsAuthenticationTicket ticket)
        {
            var identity = new identity
            {
                Id                 = Setid(ticket),
                Name               = SetName(ticket),
                Email              = SetEmail(ticket),
                Roles              = SetRoles(ticket),
                FirstName          = SetFirstName(ticket),
                LastName           = SetLastName(ticket),
                AuthenticationType = SetAuthType(ticket),
                IsAuthenticated    = SetIsAuthenticated(ticket)
            };

            return(identity);
        }
Ejemplo n.º 21
0
        // 保存游戏
        public void storeGame(int[,] arr, string time, string comment, identity winner)
        {
            if (connRecord == null)
            {
                return;
            }
            string matrix = "";

            for (int i = 0; i < 21; i++)
            {
                for (int j = 0; j < 21; j++)
                {
                    matrix += arr[i, j].ToString();
                }
            }
            string winnerStr;

            if (winner == identity.black)
            {
                winnerStr = "黑方";
            }
            else if (winner == identity.white)
            {
                winnerStr = "白方";
            }
            else if (winner == identity.man)
            {
                winnerStr = "人";
            }
            else
            {
                winnerStr = "电脑";
            }
            string sql = @"INSERT INTO GAME(time, matrix, comment, winner) VALUES(?, ?, ?, ?)";

            using (var statement = connRecord.Prepare(sql))
            {
                statement.Bind(1, time);
                statement.Bind(2, matrix);
                statement.Bind(3, comment);
                statement.Bind(4, winnerStr);
                statement.Step();
            }
        }
Ejemplo n.º 22
0
        public void printGameBoard()
        {
            //Set the second player attribute to have
            //the opposite identity of the first player
            identity secondPlayer = identity.O;

            if (firstPlayer == identity.O)
            {
                secondPlayer = identity.X;
            }

            //Display each row (loops backwards for right way up)
            for (int i = ROW - 1; i >= 0; i--)
            {
                //Write the row number
                Console.Write(i + 1);
                Console.Write(" ");

                //Display each piece
                for (int j = 0; j < COL; j++)
                {
                    char peice = board.getPieceAt(i, j);
                    if (peice == 'W')
                    {
                        Console.Write(firstPlayer);
                    }
                    else if (peice == 'B')
                    {
                        Console.Write(secondPlayer);
                    }
                    else
                    {
                        Console.Write(" ");
                    }


                    Console.Write(" "); // Temporary to see what is going on
                }
                Console.Write("\n");    // Temporary to see what is going on
            }

            //Display the column ids
            Console.Write("  A B C D E F G H\n");
        }
Ejemplo n.º 23
0
    public static animationTransformData scale(identity nIdentity, animationTransformData pose_1, float parameter, bool usingQuaternion)
    {
        animationTransformData poseresult = new animationTransformData();

        //translation: literal linear interpolation
        poseresult.localPosition = Vector3.Lerp(nIdentity.position, pose_1.localPosition, parameter);

        //scale: ditto
        poseresult.localScale = Vector3.Lerp(nIdentity.scale, pose_1.localScale, parameter);
        //rotation: slerp if quaternion (or NLERP) otherwise euler lerp
        if (usingQuaternion)
        {
            poseresult.localRotation = Quaternion.Slerp(nIdentity.rotation, pose_1.localRotation, parameter);
        }
        else
        {
            poseresult.localEulerAnglesSet(Vector3.Lerp(nIdentity.rotation.eulerAngles, pose_1.localEulerAngles(), parameter));
        }
        return(poseresult);
    }
Ejemplo n.º 24
0
        private void onDeleteLink()
        {
            EventHandler <EA_value <identity> > handler = event_linkDeleted;

            if (handler != null)
            {
                event_linkDeleted(this, new EA_value <identity>(_ID));
            }

            tpManager.clear();
            tpManager = null;

            lnkLimit = null;

            _project.getLinkFactory().event_linkFactoryDelete -= handler_factoryDelete;
            _project = null;
            _ID      = null;

            _precursor = _follower = null;
        }
Ejemplo n.º 25
0
        public bool movePiece(identity currentPlayer, Move move)
        {
            //If the current player is the first player, then white is moving
            bool isFirstsTurn = false;

            if (firstPlayer == currentPlayer)
            {
                isFirstsTurn = true;
            }

            //Flip the move if needed
            Move boardRelativeMove = flipMoveIfNeeded(move);


            //Check the move
            bool moveIsValid = checkMove(currentPlayer, move);

            if (moveIsValid)
            {
                //If the move is valid...
                //and if there is a piece from the other team that will be taken
                char pieceAtEnd = board.getPieceAt(boardRelativeMove.End.row, boardRelativeMove.End.col);
                if (pieceAtEnd != 'S')
                {
                    //set the destination as the last piece taken
                    pieceLastTaken = move.End;
                }
                else
                {
                    //Otherwise, set the piece last taken to null

                    pieceLastTaken = null;
                }
            }
            else
            {
                return(false);
            }
            //Execute the move on the Low Abstraction Board
            return(board.makeMove(isFirstsTurn, boardRelativeMove.Begin.row, boardRelativeMove.Begin.col, boardRelativeMove.End.row, boardRelativeMove.End.col, false));
        }
Ejemplo n.º 26
0
 public void setPlayer(identity iden)
 {
     playerIdentity = iden;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 写入日志
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 /// <param name="data">日志数据</param>
 /// <returns>是否成功写入缓冲区</returns>
 internal int Append(identity identity, subArray<byte> data)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity)
     {
         int value = physical.Physical.Append(data);
         if (value != 0) return value;
         Close(identity, false);
     }
     return 0;
 }
Ejemplo n.º 28
0
 public void deleteLink(identity ID)
 {
     deleteLink(ID.ID);
 }
Ejemplo n.º 29
0
 public ILink getLink(identity ID)
 {
     return(getLink(ID.ID));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// 关闭数据库文件
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 /// <param name="isWait">是否等待关闭</param>
 internal void Close(identity identity, bool isWait)
 {
     interlocked.NoCheckCompareSetSleep0(ref physicalLock);
     physicalInfo physical = physicals[identity.Index];
     try
     {
         if (physical.Identity == identity.Identity)
         {
             physicals[identity.Index].Clear();
             fileNameIndexs.Remove(physical.FileName);
             freeIndexs.Add(identity.Index);
         }
     }
     finally { physicalLock = 0; }
     if (physical.Identity == identity.Identity) physical.Close(isWait);
 }
Ejemplo n.º 31
0
 public ILink createLink(identity PrecursorID, identity FollowerID, eLnkType type)
 {
     return(createLink(PrecursorID, FollowerID, type, 0));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 刷新写入文件缓存区
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 /// <param name="isDiskFile">是否写入到磁盘文件</param>
 /// <returns>是否成功</returns>
 internal bool FlushFile(identity identity, bool isDiskFile)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity)
     {
         if (physical.Physical.FlushFile(isDiskFile)) return true;
         Close(identity, false);
     }
     return false;
 }
Ejemplo n.º 33
0
 public AIPlayer(identity newIdentity, bool isWhite) :
     base(newIdentity)
 {
     //Save whether the AI is white or not
     this.isWhite = isWhite;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// 获取数据库物理层集合唯一标识
 /// </summary>
 /// <param name="fileName">数据文件名</param>
 /// <returns>数据库物理层集合唯一标识</returns>
 internal identity GetIdentity(string fileName)
 {
     int index;
     identity identity = new identity { Index = errorIndex };
     hashString key = fileName;
     if (fileNameIndexs.TryGetValue(key, out index))
     {
         identity.Identity = physicals[index].Identity;
         int nextIndex;
         if (fileNameIndexs.TryGetValue(key, out nextIndex) && index == nextIndex) identity.Index = index;
     }
     return identity;
 }
Ejemplo n.º 35
0
 /// <summary>
 /// 数据库文件加载完毕
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 /// <returns>是否加载成功</returns>
 internal bool Loaded(identity identity, bool isLoaded)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity)
     {
         if (physical.Physical.Loaded(isLoaded)) return true;
         Close(identity, false);
     }
     return false;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// 数据库文件头数据加载
 /// </summary>
 /// <param name="identity"></param>
 /// <returns>文件数据,null表示失败</returns>
 internal subArray<byte> LoadHeader(identity identity)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity)
     {
         subArray<byte> data = physical.Physical.LoadHeader();
         if (data.array != null) return data;
         Close(identity, false);
     }
     return default(subArray<byte>);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// 等待缓存写入
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 internal void WaitBuffer(identity identity)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity) physical.Physical.WaitBuffer();
 }
Ejemplo n.º 38
0
 info = GetCacheInfo(identity);
Ejemplo n.º 39
0
 /// <summary>
 /// 创建数据库文件
 /// </summary>
 /// <param name="identity">数据库物理层唯一标识</param>
 /// <param name="header">文件头数据</param>
 /// <returns>是否创建成功</returns>
 internal bool Create(identity identity, subArray<byte> header)
 {
     physicalInfo physical = physicals[identity.Index];
     if (physical.Identity == identity.Identity)
     {
         if (physical.Physical.Create(header)) return true;
         Close(identity, false);
     }
     return false;
 }
Ejemplo n.º 40
0
 /// <summary>
 /// 判断是否相等
 /// </summary>
 /// <param name="value">比较值</param>
 /// <returns>0表示相等</returns>
 public int Equals(identity value)
 {
     return (Index ^ value.Index) | (Identity ^ value.Identity);
 }
Ejemplo n.º 41
0
 /// <summary>
 /// 索引无效是设置索引
 /// </summary>
 /// <param name="value">目标值</param>
 /// <returns>是否成功</returns>
 public bool SetIfNull(identity value)
 {
     if (Index == errorIndex)
     {
         Index = value.Index;
         Identity = value.Identity;
         return true;
     }
     return false;
 }