-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildCoen.js
131 lines (105 loc) · 4 KB
/
buildCoen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function buildCoenSchedule(incomingCredits) {
var coenCourses = [coen10, coen11, coen12, coen19];
var mathCourses = [math9, math11, math12, math13, math14, amth106, amth108, math53];
var scienceCourses = [chem11, phys31, phys32];
var coreCourses = [core];
var used = [];
// add transfer courses
updateUsed(used, incomingCredits);
// Build fall schedule
var fall = [];
// MATH slot. Can be filled with CORE if no more math to take.
var preferedCategories = [mathCourses, coreCourses];
var course = getAvailableCourse(used, fall, preferedCategories, FALL);
fall.push(course);
// SCIENCE slot. Can be filled with CORE if no more science to take.
preferedCategories = [scienceCourses, coreCourses];
course = getAvailableCourse(used, fall, preferedCategories, FALL);
fall.push(course);
// COEN slot. Prefer not to advance past coen10
preferedCategories = [[coen10], coreCourses];
course = getAvailableCourse(used, fall, preferedCategories, FALL);
fall.push(course);
// CTW slot. Hard-coded requirement
fall.push(ctw1);
// Update preqs based on classes taken in the fall
updateUsed(used, fall);
// Build winter schedule
var winter = [];
// MATH slot. Can be filled with SCIENCE or CORE if no more math to take.
preferedCategories = [mathCourses, scienceCourses, coreCourses];
course = getAvailableCourse(used, winter, preferedCategories, WINTER);
winter.push(course);
// SCIENCE slot. Can be filled with CORE if no more science to take.
preferedCategories = [scienceCourses, coreCourses];
course = getAvailableCourse(used, winter, preferedCategories, WINTER);
winter.push(course);
// COEN slot. Prefer not to advance past coen11
preferedCategories = [[coen11], coreCourses];
course = getAvailableCourse(used, winter, preferedCategories, WINTER);
winter.push(course);
// CTW slot. Hard-coded requirement
winter.push(ctw2);
// Update preqs based on classes taken in the fall
updateUsed(used, winter);
// Check if added core twice make CI
var ci = checkForCI(fall, winter);
// Add eng1 to fall or winter based on difficulty of sched or certainty of major
addEngineering1(fall, winter, eng1);
// Build spring schedule
var spring = [];
// MATH slot. Can be filled with SCIENCE or CORE if no more math to take.
preferedCategories = [mathCourses, coreCourses];
course = getAvailableCourse(used, spring, preferedCategories, SPRING);
spring.push(course);
// SCIENCE slot. Can be filled with CORE if no more science to take.
preferedCategories = [scienceCourses, coreCourses];
course = getAvailableCourse(used, spring, preferedCategories, SPRING);
spring.push(course);
// COEN slot. Can be filled with SCIENCE or CORE if no more coen to take.
preferedCategories = [[coen12], coreCourses];
course = getAvailableCourse(used, spring, preferedCategories, SPRING);
spring.push(course);
// COEN slot. Can be filled with SCIENCE or CORE if no more coen to take.
preferedCategories = [[coen19], coreCourses];
course = getAvailableCourse(used, spring, preferedCategories, SPRING);
spring.push(course);
// Check if added core twice make CI
if (!ci) {
checkForCI(winter, spring);
}
var courses = [fall, winter, spring];
return courses;
}
/* Make two consecutive CORE's a C&I sequence.
* Attempts to put the sequence on the same row.
* Returns true if made a C&I sequence, else false.
*/
function checkForCI(quarter1Courses, quarter2Courses) {
var q1Core = [];
var q2Core = [];
for (var i = 0; i < quarter1Courses.length; i++) {
if (quarter1Courses[i] == core) {
q1Core.push(i);
}
}
for (var i = 0; i < quarter2Courses.length; i++) {
if (quarter2Courses[i] == core) {
// found a common row
if ($.inArray(i, q1Core) != -1) {
quarter1Courses[i] = ci1;
quarter2Courses[i] = ci2;
return true;
}
q2Core.push(i);
}
}
// No common row. See if both quarters have core
if (q1Core.length > 0 && q2Core.length > 0) {
// Cant align C&I, just put in first available rows
quarter1Courses[q1Core[0]] = ci1;
quarter2Courses[q2Core[0]] = ci2;
return true;
}
return false;
}