예제 #1
0
        static void CustomerResponse(RequestHalfStep requestHalfStep, System.Net.Sockets.Socket client)
        {
            DBManager bdManager = new DBManager();

            bdManager.Connect();
            ChosenStep chosenStep = bdManager.GetChosenStep(requestHalfStep);

            server.Send(client, SerealizationManager.Serealize(chosenStep));
            bdManager.Close();
        }
예제 #2
0
        /// <summary>
        /// Метод для отправки пакетов серверу
        /// </summary>
        /// <param name="msg"></param>
        public void Sender(string msg)
        {
            try
            {
                TransmittedPackets.RequestHalfStep zapros = new RequestHalfStep(randomMatri(), 10);

                client.Send(SerealizationManager.Serealize(zapros));
            }
            catch
            {
                System.Console.WriteLine("Что же не так то пошло при отправке");
            }
        }
예제 #3
0
        static void server_ReceiverEvent(byte[] bytes, System.Net.Sockets.Socket client)
        {
            object otherPacket   = SerealizationManager.Deserealize(bytes);
            Type   typePacketObj = otherPacket.GetType();

            if (typePacketObj == typeof(RequestHalfStep))
            {
                CustomerResponse(otherPacket as RequestHalfStep, client);
            }

            if (typePacketObj == typeof(SaveHystoryParty))
            {
                ;
            }
        }
예제 #4
0
        public ChosenStep FindTheBestStep(RequestHalfStep requestHalfStep, DataTable table)
        {
            // if (ValidationArrangementFigures(requestHalfStep.)) {
            byte[,] tmp_ArrangementFigures;
            System.Collections.Generic.List <MementoItemAssessment> ListItemAssessment =
                new System.Collections.Generic.List <MementoItemAssessment>();
            float oneProcent = 100 / 64;
            float procent    = 0;

            for (int indexRow = 0; indexRow < table.Rows.Count; indexRow++)
            {
                byte[] array = (byte[])table.Rows[indexRow]["ArrangementFigures"];
                tmp_ArrangementFigures = (byte[, ])SerealizationManager.Deserealize(array);

                for (int i = 0; i < tmp_ArrangementFigures.GetLength(0); i++)
                {
                    for (int j = 0; j < tmp_ArrangementFigures.GetLength(1); j++)
                    {
                        if (tmp_ArrangementFigures[i, j] == requestHalfStep.ArrangementFigures[i, j])
                        {
                            procent += oneProcent;
                        }
                    }
                }
                ListItemAssessment.Add(new MementoItemAssessment(indexRow, procent));
            }

            ListItemAssessment.Sort((a, b) => a.procent.CompareTo(b.procent));
            ListItemAssessment.Reverse();
            foreach (var item in ListItemAssessment)
            {
                byte[] array = (byte[])table.Rows[item.indexRow]["ArrangementFigures"];
                tmp_ArrangementFigures = (byte[, ])SerealizationManager.Deserealize(array);
                array = (byte[])table.Rows[item.indexRow]["Position"];
                PointV2 pos = (PointV2)SerealizationManager.Deserealize(array);
                array = (byte[])table.Rows[item.indexRow]["Direction"];
                PointV2 dir = (PointV2)SerealizationManager.Deserealize(array);
                if (requestHalfStep.ArrangementFigures[pos.x, pos.y] == tmp_ArrangementFigures[pos.x, pos.y])
                {
                    return(new ChosenStep(pos, dir));
                }
            }
            throw new System.ArgumentException("На данный момент в базе нет подходящих значений");
        }
예제 #5
0
        /// <summary>
        /// Добавляет в базу обьект типа SaveHystoryParty
        /// </summary>
        /// <param name="hystoryParty"></param>
        public void Added(SaveHystoryParty hystoryParty)
        {
            if (isConnection)
            {
                MementoStep step;
                Analitic    analictic = new Analitic();
                foreach (var itemHystoryList in hystoryParty.Hystory)
                {
                    step = itemHystoryList;

                    if (analictic.ValidationArrangementFigures(step))
                    {
                        this.command = new SqlCommand("INSERT INTO StorageBestMoves(ArrangementFigures, Direction, Position, DepthOfGame)" +
                                                      "VALUES (@ArrangementFigures, @Direction, @Position, @DepthOfGame);", connection);
                        this.command.Parameters.Add("@ArrangementFigures", System.Data.SqlDbType.VarBinary);
                        this.command.Parameters["@ArrangementFigures"].Value = SerealizationManager.Serealize(step.ArrangementFigures);
                        this.command.Parameters.Add("@Direction", System.Data.SqlDbType.VarBinary);
                        this.command.Parameters["@Direction"].Value = SerealizationManager.Serealize(step.direction);
                        this.command.Parameters.Add("@Position", System.Data.SqlDbType.VarBinary);
                        this.command.Parameters["@Position"].Value = SerealizationManager.Serealize(step.position);
                        this.command.Parameters.Add("@DepthOfGame", System.Data.SqlDbType.Int);
                        this.command.Parameters["@DepthOfGame"].Value = step.stepIndex;

                        this.command.ExecuteNonQuery();
                    }
                    else
                    {
                        throw new System.ArgumentException("Index одной или нескльких фигур не соответствую заданой конигурации");
                    }
                }
            }
            else
            {
                throw new System.ArgumentException("Нет подключения к базе данных");
            }
        }