コード例 #1
0
        /// <summary>
        /// Create taking from taking dto
        /// </summary>
        /// <param name="takingDto"></param>
        /// <returns></returns>
        public TakingDto CreateTakingDto(TakingDto takingDto)
        {
            logger.Info("Create taking {@takingDto} return dto", takingDto);
            Taking taking = CreateTaking(takingDto);

            return(Converters.TakingsConverter.TakingToTakingDto(taking));
        }
コード例 #2
0
ファイル: Arity.cs プロジェクト: tspring/ioke
        private static IokeObject GetArity(IokeObject self, Taking thing)
        {
            IokeObject obj = self.runtime.Arity.AllocateCopy(null, null);

            obj.MimicsWithoutCheck(self.runtime.Arity);
            obj.Data = new Arity(thing);
            return(obj);
        }
コード例 #3
0
ファイル: Arity.cs プロジェクト: fronx/ioke
 public Arity(DefaultArgumentsDefinition argumentsDefinition)
 {
     if(argumentsDefinition == null || argumentsDefinition.IsEmpty) {
         this.taking = Taking.Nothing;
     } else {
         this.argumentsDefinition = argumentsDefinition;
     }
 }
コード例 #4
0
        /// <summary>
        /// Get taking by Id return dto
        /// </summary>
        /// <param name="takingId"></param>
        /// <returns></returns>
        public TakingDto GetTakingDtoById(int takingId)
        {
            logger.Info("Get taking dto by Id {@takingId}", takingId);

            Taking taking = GetTakingById(takingId);

            return(Converters.TakingsConverter.TakingToTakingDto(taking));
        }
コード例 #5
0
        public void Taking_Initialization_01()
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>();

            Taking <Item> itemComputing = items.Taking(0, 0);

            itemComputing.ValidateConsistency();
        }
コード例 #6
0
        /**
         * Play human taking action
         * @param a Action
         * @return Status flag
         */
        private Status Human(Taking a)
        {
            State s = m_gameTree.CurrentState();

            // human take action
            if (s == null)
            {
                return(Status.INVALIDACTION);
            }
            else
            {
                // first check if a taking action is possible at all
                if (s.TakingIsPossible(State.OppositeColor(a.Color())))
                {
                    // now check if a is a valid taking action
                    if (a.IsValid(s))
                    {
                        // play human player action a
                        m_gameTree.HumanPlayer(a);
                        if (VERBOSE)
                        {
                            Debug.WriteLine("Human has played\n\ttree size: " + m_gameTree.Size());
                        }

                        m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                        if (s.Finished())
                        {
                            if (VERBOSE)
                            {
                                Debug.WriteLine("Human has won");
                            }
                            return(Status.FINISHED);
                        }
                        else
                        {
                            return(Status.OK);
                        }
                    }
                    else
                    {
                        // ActionPM part of a is valid, just the taking is invalid
                        State sCopy = s.Clone();

                        // update state with user action
                        a.Action.Update(sCopy);

                        // redraw game board
                        return(Status.INVALIDACTION);
                    }
                }
                else
                {
                    m_view.UpdateBoard(m_gameTree.CurrentState(), a, false);
                    return(Status.OK);
                }
            }
        }
コード例 #7
0
        public void Taking_Initialization_01()
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>();

            Taking <Item> itemComputing = items.Taking(0, 0).For(consumer);;

            itemComputing.ValidateConsistency();
            consumer.Dispose();
        }
コード例 #8
0
ファイル: Arity.cs プロジェクト: tspring/ioke
 public Arity(DefaultArgumentsDefinition argumentsDefinition)
 {
     if (argumentsDefinition == null || argumentsDefinition.IsEmpty)
     {
         this.taking = Taking.Nothing;
     }
     else
     {
         this.argumentsDefinition = argumentsDefinition;
     }
 }
コード例 #9
0
        /// <summary>
        /// Delete taking
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="teacherId"></param>
        /// <param name="classRoomId"></param>
        /// <param name="studentId"></param>
        /// <returns></returns>
        public Taking DeleteTaking(int courseId, int teacherId, int classRoomId, int studentId)
        {
            logger.Info("Delete taking for course {@courseId}, teacher {@teacherId}, classroom {@classRoomId} and student {@studentId}",
                        courseId, teacherId, classRoomId, studentId);

            Taking taking = GetTaking(courseId, teacherId, classRoomId, studentId);

            db.TakingsRepository.Delete(taking);
            db.Save();
            return(taking);
        }
コード例 #10
0
        public TakingDto CreateTaking(TakingDto taking)
        {
            Taking newTaking = takingsService.Value.CreateTaking(taking);

            if (newTaking == null)
            {
                return(null);
            }

            return(Converters.TakingsConverter.TakingToTakingDto(newTaking));
        }
コード例 #11
0
 private static TeacherReportDto.StudentDto TakingToStudent(Taking taking)
 {
     return(new TeacherReportDto.StudentDto()
     {
         StudentId = taking.Student.Id,
         FirstName = taking.Student.FirstName,
         LastName = taking.Student.LastName,
         Grades = taking.Grades.Select(g => GradeToStudentGrade(g)).ToList(),
         Parents = taking.Student.StudentParents.Select(sp => StudentParentToStudentParent(sp))
     });
 }
コード例 #12
0
        public void Taking_Insert1(
            [Range(0, 2, 1)] int startIndex,
            [Range(0, 4, 1)] int count)
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>();

            Taking <Item> itemComputing = items.Taking(startIndex, count);

            itemComputing.ValidateConsistency();
            items.Insert(0, new Item());
            itemComputing.ValidateConsistency();
        }
コード例 #13
0
        public void Taking_Remove1(
            [Range(0, 2, 1)] int startIndex,
            [Range(0, 4, 1)] int count)
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>(
                new[]
            {
                new Item()
            }
                );

            Taking <Item> itemComputing = items.Taking(startIndex, count);

            itemComputing.ValidateConsistency();
            items.RemoveAt(0);
            itemComputing.ValidateConsistency();
        }
コード例 #14
0
        private void registerTaking(decimal amount, string month, string description)
        {
            DateTime nowTime = DateTime.Now;

            using (FinancialSettlementAppBase context = new FinancialSettlementAppBase())
            {
                Taking newTaking = new Taking()
                {
                    Amount      = amount,
                    Month       = month,
                    Description = description,
                    Data        = nowTime
                };
                context.taking.Add(newTaking);
                context.SaveChanges();
            }
        }
コード例 #15
0
        private void DeleteLastButton_Click(object sender, RoutedEventArgs e)
        {
            using (FinancialSettlementAppBase context = new FinancialSettlementAppBase())

                if (operationValue == "AddTakings")
                {
                    bool oldValidateOnSaveEnabled = context.Configuration.ValidateOnSaveEnabled;

                    try
                    {
                        context.Configuration.ValidateOnSaveEnabled = false;

                        Taking takingToRemove = (Taking)DisplayGrid.SelectedItem;

                        context.Entry(takingToRemove).State = System.Data.Entity.EntityState.Deleted;
                        context.SaveChanges();
                    }
                    finally
                    {
                        context.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                    }
                    viewTaking(whichTakingView(1));
                }
                else if (operationValue == "AddCost")
                {
                    bool oldValidateOnSaveEnabled = context.Configuration.ValidateOnSaveEnabled;

                    try
                    {
                        context.Configuration.ValidateOnSaveEnabled = false;

                        Cost costToRemove = (Cost)DisplayGrid.SelectedItem;

                        context.Entry(costToRemove).State = System.Data.Entity.EntityState.Deleted;
                        context.SaveChanges();
                    }
                    finally
                    {
                        context.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled;
                    }
                    viewCost(whichCostView(1));
                }
        }
コード例 #16
0
 public static TakingDto TakingToTakingDto(Taking taking)
 {
     return(new TakingDto()
     {
         TakingId = taking.Id,
         StudentId = taking.Student.Id,
         CourseId = taking.Program.Teaching.Course.Id,
         TeacherId = taking.Program.Teaching.Teacher.Id,
         TeachingId = taking.Program.Teaching.Id,
         ClassRoomId = taking.Program.ClassRoom.Id,
         ProgramId = taking.Program.Id,
         WeeklyHours = taking.Program.WeeklyHours,
         CourseName = taking.Program.Teaching.Course.Name,
         TeacherName = taking.Program.Teaching.Teacher.UserName,
         StudentName = taking.Student.UserName,
         ClassRoomName = taking.Program.ClassRoom.Name,
         SchoolGrade = taking.Program.ClassRoom.ClassGrade
     });
 }
コード例 #17
0
        public void Taking_Set(
            [Range(0, 4, 1)] int startIndex,
            [Range(0, 4, 1)] int count,
            [Range(0, 4, 1)] int index)
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>(
                new[]
            {
                new Item(),
                new Item(),
                new Item(),
                new Item(),
                new Item()
            }
                );

            Taking <Item> itemComputing = items.Taking(startIndex, count);

            itemComputing.ValidateConsistency();
            items[index] = new Item();
            itemComputing.ValidateConsistency();
        }
コード例 #18
0
        public void Taking_Insert(
            [Range(0, 4, 1)] int index,
            [Range(0, 4, 1)] int startIndex,
            [Range(0, 4, 1)] int count)
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>(
                new[]
            {
                new Item(),
                new Item(),
                new Item(),
                new Item(),
                new Item()
            }
                );

            Taking <Item> itemComputing = items.Taking(startIndex, count).For(consumer);

            itemComputing.ValidateConsistency();
            items.Insert(index, new Item());
            itemComputing.ValidateConsistency();
            consumer.Dispose();
        }
コード例 #19
0
        /// <summary>
        /// Create taking from course, teacher, classroom and student
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="teacherId"></param>
        /// <param name="classRoomId"></param>
        /// <param name="studentId"></param>
        /// <returns></returns>
        public Taking CreateTaking(int courseId, int teacherId, int classRoomId, int studentId)
        {
            logger.Info("Create taking for course {@courseId}, teacher {@teacherId}, classroom {@classRoomId} and student {@studentId}",
                        courseId, teacherId, classRoomId, studentId);
            // For creation we need the student and the program.
            Program     program = programsService.GetProgram(courseId, teacherId, classRoomId);
            StudentUser student = db.StudentsRepository.Get(s => s.Id == studentId).FirstOrDefault();

            if (program == null)
            {
                return(null);
            }

            if (student == null)
            {
                return(null);
            }

            // need to check classroom manually :(
            if (student.ClassRoomId != classRoomId)
            {
                // probably an exception but ok for now
                return(null);
            }

            Taking taking = new Taking()
            {
                Program = program,
                Student = student
            };

            db.TakingsRepository.Insert(taking);
            db.Save();

            return(taking);
        }
コード例 #20
0
        public TakingDto AssignCourseToStudent(StudentCourseDto course)
        {
            logger.Info("Service received request for assigning a course to a student {@course}", course);

            StudentUser student = db.StudentsRepository.Get(s => s.Id == course.StudentId).FirstOrDefault();

            if (student == null)
            {
                return(null);
            }

            Course theCourse = db.CoursesRepository.Get(c => c.Id == course.CourseId).FirstOrDefault();

            if (theCourse == null)
            {
                return(null);
            }

            Program program = db.ProgramsRepository.Get(p => p.Teaching.Course.Id == course.CourseId).FirstOrDefault();

            if (program == null)
            {
                return(null);
            }

            Taking taking = new Taking()
            {
                Program = program,
                Student = student
            };

            db.TakingsRepository.Insert(taking);
            db.Save();

            return(Converters.TakingsConverter.TakingToTakingDto(taking));
        }
コード例 #21
0
ファイル: State.cs プロジェクト: swordbreaker/Algd2MillGame
        /**
         * Take stone and update winner
         * @param a Action
         */
        public void Update(Taking a)
        {
            if (a == null)
            {
                throw new Exception("action is null");
            }

            byte pos   = a.TakePosition;
            var  color = a.TakeColor; // color of taken stone

            if (!IsValidTake(pos, color))
            {
                throw new Exception("invalid action");
            }

            m_board[pos] = IController.NONE;
            m_stonesOnBoard[color]--;

            if ((MovingPhase(color) || JumpingPhase(color)) && m_stonesOnBoard[color] < 3)
            {
                m_winner = a.Color();
            }
            CheckMove();
        }
コード例 #22
0
        public void Taking_Move(
            [Range(0, 4, 1)] int startIndex,
            [Range(0, 4, 1)] int count,
            [Range(0, 4, 1)] int oldIndex,
            [Range(0, 4, 1)] int newIndex)
        {
            ObservableCollection <Item> items = new ObservableCollection <Item>(
                new[]
            {
                new Item(),
                new Item(),
                new Item(),
                new Item(),
                new Item()
            }
                );

            Taking <Item> itemComputing = items.Taking(startIndex, count).IsNeededFor(consumer);

            itemComputing.ValidateConsistency();
            items.Move(oldIndex, newIndex);
            itemComputing.ValidateConsistency();
            consumer.Dispose();
        }
コード例 #23
0
ファイル: GradesService.cs プロジェクト: CabaVarga/eGradeBook
        /// <summary>
        /// Create grade with params
        /// </summary>
        /// <returns></returns>
        public Grade CreateGrade(
            int courseId, int teacherId, int classRoomId, int studentId,
            int schoolTerm, DateTime assigned,
            int gradePoint, string notes = null)
        {
            // Or go for taking directly!
            // It will eliminate any anomaly down the road
            Taking taking = takingsService.Value.GetTaking(courseId, teacherId, classRoomId, studentId);

            // School Term (or semester) check
            // For that we need a schoolYear with firstTermStartDate, firstTermEndDate, secondTermStartDate and secondTermEndDate
            // Not impossible, but quite unlikely that I will implement that until Saturday...

            // Final Grade check (if there is a final grade for a given semester, you cant assign a new grade
            // also: without final grade for first semester cant assign a grade into the new semester...

            if (taking.FinalGrades.Count() > 0)
            {
                // check this stuff here...
            }


            Grade grade = new Grade()
            {
                GradePoint = gradePoint,
                Taking     = taking,
                Assigned   = assigned,
                Notes      = notes,
                SchoolTerm = schoolTerm
            };

            db.GradesRepository.Insert(grade);
            db.Save();

            return(grade);
        }
コード例 #24
0
ファイル: Arity.cs プロジェクト: tspring/ioke
 private Arity(Taking taking)
 {
     this.taking = taking;
 }
コード例 #25
0
        /// <summary>
        /// Creates the childrens of the Node with alpha–beta pruning
        /// </summary>
        /// <param name="curHeight">current subtree height</param>
        /// <param name="height">height Subtree height</param>
        /// <param name="color">Color of next actions</param>
        /// <param name="root">Subtree root</param>
        /// <param name="rootState">Game state at root</param>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        /// <returns>The </returns>
        public int Create(int curHeight, int height, sbyte color, GameNode root, State rootState, int alpha, int beta)
        {
            if (curHeight == height || rootState.Finished())
            {
                return(rootState.Score());
            }
            var v = (color == IController.WHITE) ? int.MinValue : int.MaxValue;

            if (rootState.PlacingPhase(color))
            {
                foreach (byte position in State.TRANSPOSED)
                {
                    if (!rootState.IsValidPlace(position, color))
                    {
                        continue;
                    }
                    var nextAction = new Placing(color, position);
                    var newState   = rootState.Clone();
                    nextAction.Update(newState);
                    var childNode = Create(nextAction, root);
                    if (newState.InMill(position, color))
                    {
                        if (newState.TakingIsPossible(State.OppositeColor(color)))
                        {
                            foreach (byte takingPosition in State.TRANSPOSED)
                            {
                                if (newState.IsValidTake(takingPosition, State.OppositeColor(color)))
                                {
                                    var takeState    = rootState.Clone();
                                    var takingAction = new Taking(nextAction, takingPosition);
                                    takingAction.Update(takeState);
                                    var takingNode = Create(takingAction, root);

                                    //Minimizer
                                    if (color == IController.WHITE)
                                    {
                                        v = Math.Max(v,
                                                     Create(curHeight + 1, height, State.OppositeColor(color), takingNode,
                                                            takeState, alpha, beta));

                                        alpha = Math.Max(alpha, v);
                                    }
                                    else //Maximizer
                                    {
                                        v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode,
                                                               takeState, alpha, beta));
                                        beta = Math.Min(beta, v);
                                    }

                                    UpdateScore(takingNode, v);

                                    root.m_children.Enqueue(takingNode);
                                    if (beta <= alpha)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //Minimizer
                        if (color == IController.WHITE)
                        {
                            v = Math.Max(v,
                                         Create(curHeight + 1, height, State.OppositeColor(color), childNode,
                                                newState, alpha, beta));

                            alpha = Math.Max(alpha, v);
                        }
                        else //Maximizer
                        {
                            v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode,
                                                   newState, alpha, beta));
                            beta = Math.Min(beta, v);
                        }

                        UpdateScore(childNode, v);
                        root.m_children.Enqueue(childNode);
                        if (beta <= alpha)
                        {
                            break;
                        }
                    }
                }
            }
            else if (rootState.MovingPhase(color) || rootState.JumpingPhase(color))
            {
                for (byte i = 0; i < rootState.Board.Length; i++)
                {
                    var moves = (rootState.JumpingPhase(color)) ? State.TRANSPOSED : State.MOVES[i];
                    foreach (byte to in moves)
                    {
                        if (!rootState.IsValidMove(i, to, color))
                        {
                            continue;
                        }
                        var nextAction = new Moving(color, i, to);
                        var childNode  = Create(nextAction, root);
                        var newState   = rootState.Clone();
                        childNode.Data().Update(newState);
                        if (newState.InMill(to, color))
                        {
                            if (newState.TakingIsPossible(State.OppositeColor(color)))
                            {
                                foreach (byte takingPosition in State.TRANSPOSED)
                                {
                                    if (!newState.IsValidTake(takingPosition, State.OppositeColor(color)))
                                    {
                                        continue;
                                    }
                                    var takingNode = Create(new Taking(nextAction, takingPosition), root);
                                    var takeState  = rootState.Clone();
                                    takingNode.Data().Update(takeState);

                                    //Minimizer
                                    if (color == IController.WHITE)
                                    {
                                        v = Math.Max(v,
                                                     Create(curHeight + 1, height, State.OppositeColor(color), takingNode,
                                                            takeState, alpha, beta));

                                        alpha = Math.Max(alpha, v);
                                    }
                                    else //Maximizer
                                    {
                                        v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), takingNode,
                                                               takeState, alpha, beta));
                                        beta = Math.Min(beta, v);
                                    }

                                    UpdateScore(takingNode, v);
                                    root.m_children.Enqueue(takingNode);
                                    if (beta <= alpha)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Minimizer
                            if (color == IController.WHITE)
                            {
                                v = Math.Max(v,
                                             Create(curHeight + 1, height, State.OppositeColor(color), childNode,
                                                    newState, alpha, beta));

                                alpha = Math.Max(alpha, v);
                            }
                            else //Maximizer
                            {
                                v = Math.Min(v, Create(curHeight + 1, height, State.OppositeColor(color), childNode,
                                                       newState, alpha, beta));
                                beta = Math.Min(beta, v);
                            }

                            UpdateScore(childNode, v);
                            root.m_children.Enqueue(childNode);
                            if (beta <= alpha)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(v);
        }
コード例 #26
0
ファイル: Arity.cs プロジェクト: fronx/ioke
 private static IokeObject GetArity(IokeObject self, Taking thing)
 {
     IokeObject obj = self.runtime.Arity.AllocateCopy(null, null);
     obj.MimicsWithoutCheck(self.runtime.Arity);
     obj.Data = new Arity(thing);
     return obj;
 }
コード例 #27
0
ファイル: Arity.cs プロジェクト: fronx/ioke
 private Arity(Taking taking)
 {
     this.taking = taking;
 }